Fix realpath not to die on non-existing files (bug #5790)

Thanks to china@thewrittenword.com
This commit is contained in:
Stanislav Malyshev 2000-07-27 13:48:50 +00:00
parent 5ec120366c
commit ba8d49dce7

View file

@ -251,15 +251,18 @@ char *php_realpath(char *path, char resolved_path []) {
} }
/* Check if the resolved path is a directory */ /* Check if the resolved path is a directory */
if (V_STAT(path_construction, &filestat) != 0) return NULL; if (V_STAT(path_construction, &filestat) != 0) {
if (S_ISDIR(filestat.st_mode)) { if (errno != ENOENT) return NULL;
/* It's a directory, append a / if needed */ } else {
if (*(writepos-1) != '/') { if (S_ISDIR(filestat.st_mode)) {
/* Check for overflow */ /* It's a directory, append a / if needed */
if ((strlen(workpos) + 2) >= MAXPATHLEN) return NULL; if (*(writepos-1) != '/') {
/* C heck for overflow */
*writepos++ = '/'; if ((strlen(workpos) + 2) >= MAXPATHLEN) return NULL;
*writepos = 0;
*writepos++ = '/';
*writepos = 0;
}
} }
} }