mirror of
https://github.com/php/php-src.git
synced 2025-08-19 17:04:47 +02:00
- Centralize more fopen-wrappers functionality.
This commit is contained in:
parent
53a3f074ab
commit
0c57780b11
1 changed files with 8 additions and 19 deletions
|
@ -251,6 +251,9 @@ FILE *php_fopen_and_set_opened_path(const char *path, char *mode, char **opened_
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
if (php_check_open_basedir((char *)path)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
fp = V_FOPEN(path, mode);
|
fp = V_FOPEN(path, mode);
|
||||||
if (fp && opened_path) {
|
if (fp && opened_path) {
|
||||||
*opened_path = expand_filepath(path,NULL);
|
*opened_path = expand_filepath(path,NULL);
|
||||||
|
@ -280,9 +283,6 @@ PHPAPI FILE *php_fopen_wrapper(char *path, char *mode, int options, int *issock,
|
||||||
if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!php_checkuid(path, mode, 0))) {
|
if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!php_checkuid(path, mode, 0))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (php_check_open_basedir(path)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return php_fopen_and_set_opened_path(path, mode, opened_path);
|
return php_fopen_and_set_opened_path(path, mode, opened_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,6 +396,7 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **
|
||||||
char *pathbuf, *ptr, *end;
|
char *pathbuf, *ptr, *end;
|
||||||
char trypath[MAXPATHLEN + 1];
|
char trypath[MAXPATHLEN + 1];
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
FILE *fp;
|
||||||
PLS_FETCH();
|
PLS_FETCH();
|
||||||
|
|
||||||
if (opened_path) {
|
if (opened_path) {
|
||||||
|
@ -407,8 +408,6 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **
|
||||||
if (PG(safe_mode) && (!php_checkuid(filename, mode, 0))) {
|
if (PG(safe_mode) && (!php_checkuid(filename, mode, 0))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (php_check_open_basedir(filename)) return NULL;
|
|
||||||
|
|
||||||
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
||||||
}
|
}
|
||||||
/* Absolute path open - prepend document_root in safe mode */
|
/* Absolute path open - prepend document_root in safe mode */
|
||||||
|
@ -426,12 +425,8 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **
|
||||||
if (!php_checkuid(trypath, mode, 0)) {
|
if (!php_checkuid(trypath, mode, 0)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (php_check_open_basedir(trypath)) return NULL;
|
|
||||||
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
||||||
} else {
|
} else {
|
||||||
if (php_check_open_basedir(filename)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -439,9 +434,6 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **
|
||||||
if (PG(safe_mode) && (!php_checkuid(filename, mode, 0))) {
|
if (PG(safe_mode) && (!php_checkuid(filename, mode, 0))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (php_check_open_basedir(filename)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
return php_fopen_and_set_opened_path(filename, mode, opened_path);
|
||||||
}
|
}
|
||||||
pathbuf = estrdup(path);
|
pathbuf = estrdup(path);
|
||||||
|
@ -465,9 +457,10 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!php_check_open_basedir(trypath)) {
|
fp = php_fopen_and_set_opened_path(trypath, mode, opened_path);
|
||||||
|
if (fp) {
|
||||||
efree(pathbuf);
|
efree(pathbuf);
|
||||||
return php_fopen_and_set_opened_path(trypath, mode, opened_path);
|
return fp;
|
||||||
}
|
}
|
||||||
ptr = end;
|
ptr = end;
|
||||||
}
|
}
|
||||||
|
@ -1013,14 +1006,10 @@ static FILE *php_fopen_url_wrapper(const char *path, char *mode, int options, in
|
||||||
} else {
|
} else {
|
||||||
if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!php_checkuid(path, mode, 0))) {
|
if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!php_checkuid(path, mode, 0))) {
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
} else {
|
|
||||||
if (php_check_open_basedir((char *) path)) {
|
|
||||||
fp = NULL;
|
|
||||||
} else {
|
} else {
|
||||||
fp = php_fopen_and_set_opened_path(path, mode, opened_path);
|
fp = php_fopen_and_set_opened_path(path, mode, opened_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return (fp);
|
return (fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue