summaryrefslogtreecommitdiff
path: root/main/fopen_wrappers.c
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2001-07-16 13:48:07 +0000
committerZeev Suraski <zeev@php.net>2001-07-16 13:48:07 +0000
commitba1249dc8e1e63cafdd52663a3e9bfa4bd542e07 (patch)
tree06b487f196902cb740b622c19176cc3b5c8532e6 /main/fopen_wrappers.c
parent407fd77c2097c7d1ca6b26b183a458e01dfb6722 (diff)
downloadphp-git-ba1249dc8e1e63cafdd52663a3e9bfa4bd542e07.tar.gz
Fix the crash Joey found
Diffstat (limited to 'main/fopen_wrappers.c')
-rw-r--r--main/fopen_wrappers.c22
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);
}