mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
revert file: support in preparation for simpler patch
This commit is contained in:
parent
e5103d764a
commit
0029a45795
@ -22,7 +22,6 @@
|
|||||||
#include "php_globals.h"
|
#include "php_globals.h"
|
||||||
#include "php_network.h"
|
#include "php_network.h"
|
||||||
#include "php_open_temporary_file.h"
|
#include "php_open_temporary_file.h"
|
||||||
#include "ext/standard/url.h"
|
|
||||||
#include "ext/standard/file.h"
|
#include "ext/standard/file.h"
|
||||||
#include "ext/standard/flock_compat.h"
|
#include "ext/standard/flock_compat.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -87,18 +86,13 @@ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags)
|
|||||||
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC)
|
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC)
|
||||||
{
|
{
|
||||||
char *realpath = NULL;
|
char *realpath = NULL;
|
||||||
php_url *url = NULL;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int open_flags;
|
int open_flags;
|
||||||
int fd;
|
int fd;
|
||||||
php_stream *ret = NULL;
|
php_stream *ret;
|
||||||
int persistent = options & STREAM_OPEN_PERSISTENT;
|
int persistent = options & STREAM_OPEN_PERSISTENT;
|
||||||
char *persistent_id = NULL;
|
char *persistent_id = NULL;
|
||||||
|
|
||||||
if(!filename) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILURE == php_stream_parse_fopen_modes(mode, &open_flags)) {
|
if (FAILURE == php_stream_parse_fopen_modes(mode, &open_flags)) {
|
||||||
if (options & REPORT_ERRORS) {
|
if (options & REPORT_ERRORS) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "`%s' is not a valid mode for fopen", mode);
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "`%s' is not a valid mode for fopen", mode);
|
||||||
@ -106,13 +100,8 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncasecmp(filename, "file", 4)) {
|
|
||||||
url = php_url_parse((char *)filename);
|
|
||||||
filename = url->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((realpath = expand_filepath(filename, NULL TSRMLS_CC)) == NULL) {
|
if ((realpath = expand_filepath(filename, NULL TSRMLS_CC)) == NULL) {
|
||||||
goto stream_fopen_done;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (persistent) {
|
if (persistent) {
|
||||||
@ -123,10 +112,14 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
|
|||||||
*opened_path = realpath;
|
*opened_path = realpath;
|
||||||
realpath = NULL;
|
realpath = NULL;
|
||||||
}
|
}
|
||||||
|
if (realpath) {
|
||||||
|
efree(realpath);
|
||||||
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
||||||
case PHP_STREAM_PERSISTENT_FAILURE:
|
case PHP_STREAM_PERSISTENT_FAILURE:
|
||||||
goto stream_fopen_done;
|
efree(persistent_id);;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,22 +143,22 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
|
|||||||
*opened_path = realpath;
|
*opened_path = realpath;
|
||||||
realpath = NULL;
|
realpath = NULL;
|
||||||
}
|
}
|
||||||
goto stream_fopen_done;
|
if (realpath) {
|
||||||
|
efree(realpath);
|
||||||
|
}
|
||||||
|
if (persistent_id) {
|
||||||
|
efree(persistent_id);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
err:
|
err:
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
stream_fopen_done:
|
efree(realpath);
|
||||||
if (realpath) {
|
|
||||||
efree(realpath);
|
|
||||||
}
|
|
||||||
if (url) {
|
|
||||||
efree(url);
|
|
||||||
}
|
|
||||||
if (persistent_id) {
|
if (persistent_id) {
|
||||||
efree(persistent_id);
|
efree(persistent_id);
|
||||||
}
|
}
|
||||||
return ret;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -966,7 +959,6 @@ PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char
|
|||||||
{
|
{
|
||||||
/* code ripped off from fopen_wrappers.c */
|
/* code ripped off from fopen_wrappers.c */
|
||||||
char *pathbuf, *ptr, *end;
|
char *pathbuf, *ptr, *end;
|
||||||
php_url *url = NULL;
|
|
||||||
char *exec_fname;
|
char *exec_fname;
|
||||||
char trypath[MAXPATHLEN];
|
char trypath[MAXPATHLEN];
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
@ -983,11 +975,6 @@ PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncasecmp(filename, "file", 4)) {
|
|
||||||
url = php_url_parse((char *)filename);
|
|
||||||
filename = url->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
filename_length = strlen(filename);
|
filename_length = strlen(filename);
|
||||||
|
|
||||||
/* Relative path open */
|
/* Relative path open */
|
||||||
@ -1003,16 +990,13 @@ PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char
|
|||||||
|
|
||||||
|
|
||||||
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
|
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
|
if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
stream = php_stream_fopen_rel(filename, mode, opened_path, options);
|
return php_stream_fopen_rel(filename, mode, opened_path, options);
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1026,23 +1010,17 @@ not_relative_path:
|
|||||||
if (IS_ABSOLUTE_PATH(filename, filename_length)) {
|
if (IS_ABSOLUTE_PATH(filename, filename_length)) {
|
||||||
|
|
||||||
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
|
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((php_check_safe_mode_include_dir(filename TSRMLS_CC)) == 0) {
|
if ((php_check_safe_mode_include_dir(filename TSRMLS_CC)) == 0)
|
||||||
/* filename is in safe_mode_include_dir (or subdir) */
|
/* filename is in safe_mode_include_dir (or subdir) */
|
||||||
stream = php_stream_fopen_rel(filename, mode, opened_path, options);
|
return php_stream_fopen_rel(filename, mode, opened_path, options);
|
||||||
goto stream_done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
|
if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM)))
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream = php_stream_fopen_rel(filename, mode, opened_path, options);
|
return php_stream_fopen_rel(filename, mode, opened_path, options);
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
@ -1058,36 +1036,29 @@ not_relative_path:
|
|||||||
free(cwd);
|
free(cwd);
|
||||||
|
|
||||||
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) {
|
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) {
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC)) == 0) {
|
if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC)) == 0) {
|
||||||
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
|
return php_stream_fopen_rel(trypath, mode, opened_path, options);
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
if (PG(safe_mode) && (!php_checkuid(trypath, mode, CHECKUID_CHECK_MODE_PARAM))) {
|
if (PG(safe_mode) && (!php_checkuid(trypath, mode, CHECKUID_CHECK_MODE_PARAM))) {
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
|
return php_stream_fopen_rel(trypath, mode, opened_path, options);
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!path || (path && !*path)) {
|
if (!path || (path && !*path)) {
|
||||||
|
|
||||||
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
|
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
|
if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
|
||||||
stream = NULL;
|
return NULL;
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
stream = php_stream_fopen_rel(filename, mode, opened_path, options);
|
return php_stream_fopen_rel(filename, mode, opened_path, options);
|
||||||
goto stream_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check in provided path */
|
/* check in provided path */
|
||||||
@ -1146,18 +1117,12 @@ not_relative_path:
|
|||||||
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
|
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
|
||||||
if (stream) {
|
if (stream) {
|
||||||
stream_done:
|
stream_done:
|
||||||
if (url) {
|
|
||||||
efree(url);
|
|
||||||
}
|
|
||||||
efree(pathbuf);
|
efree(pathbuf);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
ptr = end;
|
ptr = end;
|
||||||
} /* end provided path */
|
} /* end provided path */
|
||||||
|
|
||||||
if (url) {
|
|
||||||
efree(url);
|
|
||||||
}
|
|
||||||
efree(pathbuf);
|
efree(pathbuf);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user