|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[1999-12-31 14:35 UTC] djm at web dot us dot uu dot net
I'm trying to track down exactly what document_root does, and under what circumstances. I found the following inconsistency:
If PHP3_URL_FOPEN is defined, then php3_fopen_wrapper runs php3_fopen_url_wrapper, which does:
if (options & USE_PATH) {
fp = php3_fopen_with_path((char *) path, mode, PG(include_path), NULL);
Otherwise, it runs
if (options & USE_PATH && PG(include_path) != NULL) {
return php3_fopen_with_path(path, mode, PG(include_path), NULL);
It seems to me that those two if statements should be identical, so the semantics of include_path and document_root don't depend on whether PHP3_URL_FOPEN is defined.
I don't know which one is what was intended, however.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 00:00:02 2025 UTC |
I now believe that both of those if statements are wrong. php3_fopen_with_path should always be run, because it is the only place that checks doc_root. Experimenting shows that the PHP function fopen does not use doc_root, at least when configured the way I have it. If include_path is not set, php3_fopen_wrapper does the same thing as the alternative code blocks in these two statements, so those blocks are redundant. (BTW, I do have safe_mode on, and open_basedir set to the same value as doc_root.) Also, the check in php3_fopen_with_path for a relative file name is wrong, because it fails for files with names like ".cshrc" or "....", and it doesn't handle ".." either. Here are patches to make it work the way it seems to me it should. --- fopen-wrappers.c 1999/12/30 22:31:12 1.1.1.2 +++ fopen-wrappers.c 1999/12/31 21:26:54 @@ -194,16 +194,7 @@ } #endif - if (options & USE_PATH && PG(include_path) != NULL) { - return php3_fopen_with_path(path, mode, PG(include_path), NULL); - } else { - if(!strcmp(mode,"r") || !strcmp(mode,"r+")) cm=0; - if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!_php3_checkuid(path, cm))) { - return NULL; - } - if (_php3_check_open_basedir(path)) return NULL; - return fopen(path, mode); - } + return php3_fopen_with_path(path, mode, PG(include_path), NULL); } #if CGI_BINARY || FHTTPD || USE_SAPI @@ -324,8 +315,9 @@ if (opened_path) { *opened_path = NULL; } - /* Relative path open */ - if (*filename == '.') { + /* Relative path open; never use path */ + if ((filename[0] == '.' && filename[1] == '/') + || (filename[0] == '.' && filename[1] == '.' && filename[2] == '/')) { if (PG(safe_mode) && (!_php3_checkuid(filename, cm))) { return NULL; } @@ -886,23 +878,8 @@ } else { PLS_FETCH(); - - if (options & USE_PATH) { - fp = php3_fopen_with_path((char *) path, mode, PG(include_path), NULL); - } else { - int cm=2; - if(!strcmp(mode,"r") || !strcmp(mode,"r+")) cm=0; - if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!_php3_checkuid(path, cm))) { - fp = NULL; - } else { - if (_php3_check_open_basedir((char *) path)) { - fp = NULL; - } else { - fp = fopen(path, mode); - } - } - } + fp = php3_fopen_with_path((char *) path, mode, PG(include_path), NULL); *issock = 0; return (fp);Here's a slightly more efficient patch for preventing relative paths from being searched for in include_path. @@ -315,9 +315,10 @@ if (opened_path) { *opened_path = NULL; } - /* Relative path open; never use path */ - if ((filename[0] == '.' && filename[1] == '/') - || (filename[0] == '.' && filename[1] == '.' && filename[2] == '/')) { + /* Relative path; do not search for the file in "path" */ + if (filename[0] == '.' && + (filename[1] == '/' + || (filename[1] == '.' && filename[2] == '/'))) { if (PG(safe_mode) && (!_php3_checkuid(filename, cm))) { return NULL; }