diff options
author | Zeev Suraski <zeev@php.net> | 2001-07-16 13:48:07 +0000 |
---|---|---|
committer | Zeev Suraski <zeev@php.net> | 2001-07-16 13:48:07 +0000 |
commit | ba1249dc8e1e63cafdd52663a3e9bfa4bd542e07 (patch) | |
tree | 06b487f196902cb740b622c19176cc3b5c8532e6 /main/fopen_wrappers.c | |
parent | 407fd77c2097c7d1ca6b26b183a458e01dfb6722 (diff) | |
download | php-git-ba1249dc8e1e63cafdd52663a3e9bfa4bd542e07.tar.gz |
Fix the crash Joey found
Diffstat (limited to 'main/fopen_wrappers.c')
-rw-r--r-- | main/fopen_wrappers.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 85d56fbb2b..c4c8e484e7 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -465,18 +465,18 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** exec_fname_length = strlen(exec_fname); path_length = strlen(path); - while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])) { + while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); + if ((exec_fname && exec_fname[0] == '[') + || exec_fname_length<=0) { + /* [no active file] or no path */ + pathbuf = estrdup(path); + } else { + pathbuf = (char *) emalloc(exec_fname_length + path_length +1 +1); + memcpy(pathbuf, path, path_length); + pathbuf[path_length] = DEFAULT_DIR_SEPARATOR; + memcpy(pathbuf+path_length+1, exec_fname, exec_fname_length); + pathbuf[path_length + exec_fname_length +1] = '\0'; } - if (exec_fname && exec_fname[0] == '[') { - /* [no active file] */ - exec_fname_length = 0; - } - - pathbuf = (char *) emalloc(exec_fname_length + path_length +1 +1); - memcpy(pathbuf, path, path_length); - pathbuf[path_length] = DEFAULT_DIR_SEPARATOR; - memcpy(pathbuf+path_length+1, exec_fname, exec_fname_length); - pathbuf[path_length + exec_fname_length +1] = '\0'; } else { pathbuf = estrdup(path); } |