Skip to content

Commit 4b54140

Browse files
author
Andi Gutmans
committed
- Commit patch which checks for an include file in the calling scripts'
current working directory if everything else fails (include_path). - Right now this also effects things like opening php.ini. It'll now always check in the current working directory for php.ini. I think this doesn't screw up todays behavior.
1 parent 203ea6c commit 4b54140

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

main/fopen_wrappers.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,39 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **
443443
}
444444
ptr = end;
445445
}
446+
446447
efree(pathbuf);
447-
return NULL;
448+
449+
{
450+
char *exec_fname;
451+
int exec_fname_len;
452+
char *filename_dir;
453+
ELS_FETCH();
454+
455+
exec_fname = zend_get_executed_filename(ELS_C);
456+
exec_fname_len = strlen(exec_fname);
457+
458+
pathbuf = (char *) emalloc(exec_fname_len+filename_length+1+1); /* Over allocate to save time */
459+
memcpy(pathbuf, exec_fname, exec_fname_len+1);
460+
461+
while ((--exec_fname_len >= 0) && !IS_SLASH(pathbuf[exec_fname_len])) {
462+
}
463+
pathbuf[exec_fname_len] = DEFAULT_SLASH;
464+
memcpy(&pathbuf[exec_fname_len+1], filename, filename_length+1);
465+
466+
fprintf(stderr,"Trying to open %s\n", pathbuf);
467+
468+
if (PG(safe_mode)) {
469+
if (VCWD_STAT(pathbuf, &sb) == 0 && (!php_checkuid(pathbuf, mode, CHECKUID_CHECK_MODE_PARAM))) {
470+
efree(pathbuf);
471+
return NULL;
472+
}
473+
}
474+
fp = php_fopen_and_set_opened_path(pathbuf, mode, opened_path);
475+
efree(pathbuf);
476+
return fp;
477+
}
478+
return NULL; /* Not really needed anymore */
448479
}
449480
/* }}} */
450481

0 commit comments

Comments
 (0)