mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
Fix realpath not to die on non-existing files (bug #5790)
Thanks to china@thewrittenword.com
This commit is contained in:
parent
5ec120366c
commit
ba8d49dce7
1 changed files with 12 additions and 9 deletions
|
@ -251,15 +251,18 @@ char *php_realpath(char *path, char resolved_path []) {
|
|||
}
|
||||
|
||||
/* Check if the resolved path is a directory */
|
||||
if (V_STAT(path_construction, &filestat) != 0) return NULL;
|
||||
if (S_ISDIR(filestat.st_mode)) {
|
||||
/* It's a directory, append a / if needed */
|
||||
if (*(writepos-1) != '/') {
|
||||
/* Check for overflow */
|
||||
if ((strlen(workpos) + 2) >= MAXPATHLEN) return NULL;
|
||||
|
||||
*writepos++ = '/';
|
||||
*writepos = 0;
|
||||
if (V_STAT(path_construction, &filestat) != 0) {
|
||||
if (errno != ENOENT) return NULL;
|
||||
} else {
|
||||
if (S_ISDIR(filestat.st_mode)) {
|
||||
/* It's a directory, append a / if needed */
|
||||
if (*(writepos-1) != '/') {
|
||||
/* C heck for overflow */
|
||||
if ((strlen(workpos) + 2) >= MAXPATHLEN) return NULL;
|
||||
|
||||
*writepos++ = '/';
|
||||
*writepos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue