version 1.1, 2012/02/21 23:48:02
|
version 1.1.1.4, 2014/06/15 20:03:57
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2014 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 70
|
Line 70
|
#endif |
#endif |
|
|
#include "ext/standard/head.h" |
#include "ext/standard/head.h" |
#include "safe_mode.h" |
|
#include "php_string.h" |
#include "php_string.h" |
#include "file.h" |
#include "file.h" |
|
|
Line 136 php_file_globals file_globals;
|
Line 135 php_file_globals file_globals;
|
|
|
/* {{{ ZTS-stuff / Globals / Prototypes */ |
/* {{{ ZTS-stuff / Globals / Prototypes */ |
|
|
/* sharing globals is *evil* */ | /* sharing globals is *evil* */ |
static int le_stream_context = FAILURE; |
static int le_stream_context = FAILURE; |
|
|
PHPAPI int php_le_stream_context(void) | PHPAPI int php_le_stream_context(TSRMLS_D) |
{ |
{ |
return le_stream_context; |
return le_stream_context; |
} |
} |
Line 162 static void file_globals_ctor(php_file_globals *file_g
|
Line 161 static void file_globals_ctor(php_file_globals *file_g
|
FG(pclose_ret) = 0; |
FG(pclose_ret) = 0; |
FG(user_stream_current_filename) = NULL; |
FG(user_stream_current_filename) = NULL; |
FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; |
FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; |
|
FG(wrapper_errors) = NULL; |
} |
} |
|
|
static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC) |
static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC) |
Line 170 static void file_globals_dtor(php_file_globals *file_g
|
Line 170 static void file_globals_dtor(php_file_globals *file_g
|
|
|
PHP_INI_BEGIN() |
PHP_INI_BEGIN() |
STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals) |
STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals) |
PHP_INI_ENTRY("from", NULL, PHP_INI_ALL, NULL) | STD_PHP_INI_ENTRY("from", NULL, PHP_INI_ALL, OnUpdateString, from_address, php_file_globals, file_globals) |
STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateLong, default_socket_timeout, php_file_globals, file_globals) |
STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateLong, default_socket_timeout, php_file_globals, file_globals) |
STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateLong, auto_detect_line_endings, php_file_globals, file_globals) |
STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateLong, auto_detect_line_endings, php_file_globals, file_globals) |
PHP_INI_END() |
PHP_INI_END() |
Line 237 PHP_MINIT_FUNCTION(file)
|
Line 237 PHP_MINIT_FUNCTION(file)
|
REGISTER_LONG_CONSTANT("STREAM_PF_INET", AF_INET, CONST_CS|CONST_PERSISTENT); |
REGISTER_LONG_CONSTANT("STREAM_PF_INET", AF_INET, CONST_CS|CONST_PERSISTENT); |
#endif |
#endif |
|
|
#ifdef PF_INET6 | #if HAVE_IPV6 |
| # ifdef PF_INET6 |
REGISTER_LONG_CONSTANT("STREAM_PF_INET6", PF_INET6, CONST_CS|CONST_PERSISTENT); |
REGISTER_LONG_CONSTANT("STREAM_PF_INET6", PF_INET6, CONST_CS|CONST_PERSISTENT); |
#elif defined(AF_INET6) | # elif defined(AF_INET6) |
REGISTER_LONG_CONSTANT("STREAM_PF_INET6", AF_INET6, CONST_CS|CONST_PERSISTENT); |
REGISTER_LONG_CONSTANT("STREAM_PF_INET6", AF_INET6, CONST_CS|CONST_PERSISTENT); |
|
# endif |
#endif |
#endif |
|
|
#ifdef PF_UNIX |
#ifdef PF_UNIX |
Line 382 PHP_FUNCTION(get_meta_tags)
|
Line 384 PHP_FUNCTION(get_meta_tags)
|
memset(&md, 0, sizeof(md)); |
memset(&md, 0, sizeof(md)); |
|
|
/* Parse arguments */ |
/* Parse arguments */ |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &filename_len, &use_include_path) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|b", &filename, &filename_len, &use_include_path) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
md.stream = php_stream_open_wrapper(filename, "rb", |
md.stream = php_stream_open_wrapper(filename, "rb", |
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, | (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, |
NULL); |
NULL); |
if (!md.stream) { |
if (!md.stream) { |
RETURN_FALSE; |
RETURN_FALSE; |
Line 426 PHP_FUNCTION(get_meta_tags)
|
Line 424 PHP_FUNCTION(get_meta_tags)
|
have_name = 1; |
have_name = 1; |
} else if (saw_content) { |
} else if (saw_content) { |
STR_FREE(value); |
STR_FREE(value); |
/* Get the CONTENT attr (Single word attr, non-quoted) */ | value = estrndup(md.token_data, md.token_len); |
if (PG(magic_quotes_runtime)) { | |
value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC); | |
} else { | |
value = estrndup(md.token_data, md.token_len); | |
} | |
| |
have_content = 1; |
have_content = 1; |
} |
} |
|
|
Line 466 PHP_FUNCTION(get_meta_tags)
|
Line 458 PHP_FUNCTION(get_meta_tags)
|
have_name = 1; |
have_name = 1; |
} else if (saw_content) { |
} else if (saw_content) { |
STR_FREE(value); |
STR_FREE(value); |
/* Get the CONTENT attr (Single word attr, non-quoted) */ | value = estrndup(md.token_data, md.token_len); |
if (PG(magic_quotes_runtime)) { | |
value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC); | |
} else { | |
value = estrndup(md.token_data, md.token_len); | |
} | |
| |
have_content = 1; |
have_content = 1; |
} |
} |
|
|
Line 539 PHP_FUNCTION(file_get_contents)
|
Line 525 PHP_FUNCTION(file_get_contents)
|
php_stream_context *context = NULL; |
php_stream_context *context = NULL; |
|
|
/* Parse arguments */ |
/* Parse arguments */ |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!ll", &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|br!ll", &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (ZEND_NUM_ARGS() == 5 && maxlen < 0) { |
if (ZEND_NUM_ARGS() == 5 && maxlen < 0) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "length must be greater than or equal to zero"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "length must be greater than or equal to zero"); |
RETURN_FALSE; |
RETURN_FALSE; |
Line 555 PHP_FUNCTION(file_get_contents)
|
Line 537 PHP_FUNCTION(file_get_contents)
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
|
|
stream = php_stream_open_wrapper_ex(filename, "rb", |
stream = php_stream_open_wrapper_ex(filename, "rb", |
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, | (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, |
NULL, context); |
NULL, context); |
if (!stream) { |
if (!stream) { |
RETURN_FALSE; |
RETURN_FALSE; |
Line 568 PHP_FUNCTION(file_get_contents)
|
Line 550 PHP_FUNCTION(file_get_contents)
|
} |
} |
|
|
if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) { |
if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) { |
|
|
if (PG(magic_quotes_runtime)) { |
|
contents = php_addslashes(contents, len, &len, 1 TSRMLS_CC); /* 1 = free source string */ |
|
} |
|
|
|
RETVAL_STRINGL(contents, len, 0); |
RETVAL_STRINGL(contents, len, 0); |
} else if (len == 0) { |
} else if (len == 0) { |
RETVAL_EMPTY_STRING(); |
RETVAL_EMPTY_STRING(); |
Line 599 PHP_FUNCTION(file_put_contents)
|
Line 576 PHP_FUNCTION(file_put_contents)
|
php_stream *srcstream = NULL; |
php_stream *srcstream = NULL; |
char mode[3] = "wb"; |
char mode[3] = "wb"; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (Z_TYPE_P(data) == IS_RESOURCE) { |
if (Z_TYPE_P(data) == IS_RESOURCE) { |
php_stream_from_zval(srcstream, &data); |
php_stream_from_zval(srcstream, &data); |
} |
} |
Line 627 PHP_FUNCTION(file_put_contents)
|
Line 600 PHP_FUNCTION(file_put_contents)
|
} |
} |
mode[2] = '\0'; |
mode[2] = '\0'; |
|
|
stream = php_stream_open_wrapper_ex(filename, mode, ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); | stream = php_stream_open_wrapper_ex(filename, mode, ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | REPORT_ERRORS, NULL, context); |
if (stream == NULL) { |
if (stream == NULL) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
Line 735 PHP_FUNCTION(file)
|
Line 708 PHP_FUNCTION(file)
|
{ |
{ |
char *filename; |
char *filename; |
int filename_len; |
int filename_len; |
char *slashed, *target_buf=NULL, *p, *s, *e; | char *target_buf=NULL, *p, *s, *e; |
register int i = 0; |
register int i = 0; |
int target_len, len; | int target_len; |
char eol_marker = '\n'; |
char eol_marker = '\n'; |
long flags = 0; |
long flags = 0; |
zend_bool use_include_path; |
zend_bool use_include_path; |
Line 748 PHP_FUNCTION(file)
|
Line 721 PHP_FUNCTION(file)
|
php_stream_context *context = NULL; |
php_stream_context *context = NULL; |
|
|
/* Parse arguments */ |
/* Parse arguments */ |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lr!", &filename, &filename_len, &flags, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|lr!", &filename, &filename_len, &flags, &zcontext) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) { |
if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%ld' flag is not supported", flags); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%ld' flag is not supported", flags); |
RETURN_FALSE; |
RETURN_FALSE; |
Line 767 PHP_FUNCTION(file)
|
Line 735 PHP_FUNCTION(file)
|
|
|
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); |
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); |
|
|
stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); | stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, context); |
if (!stream) { |
if (!stream) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
Line 794 PHP_FUNCTION(file)
|
Line 762 PHP_FUNCTION(file)
|
do { |
do { |
p++; |
p++; |
parse_eol: |
parse_eol: |
if (PG(magic_quotes_runtime)) { | add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0); |
/* s is in target_buf which is freed at the end of the function */ | |
slashed = php_addslashes(s, (p-s), &len, 0 TSRMLS_CC); | |
add_index_stringl(return_value, i++, slashed, len, 0); | |
} else { | |
add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0); | |
} | |
s = p; |
s = p; |
} while ((p = memchr(p, eol_marker, (e-p)))); |
} while ((p = memchr(p, eol_marker, (e-p)))); |
} else { |
} else { |
Line 813 parse_eol:
|
Line 775 parse_eol:
|
s = ++p; |
s = ++p; |
continue; |
continue; |
} |
} |
if (PG(magic_quotes_runtime)) { | add_index_stringl(return_value, i++, estrndup(s, p-s-windows_eol), p-s-windows_eol, 0); |
/* s is in target_buf which is freed at the end of the function */ | |
slashed = php_addslashes(s, (p-s-windows_eol), &len, 0 TSRMLS_CC); | |
add_index_stringl(return_value, i++, slashed, len, 0); | |
} else { | |
add_index_stringl(return_value, i++, estrndup(s, p-s-windows_eol), p-s-windows_eol, 0); | |
} | |
s = ++p; |
s = ++p; |
} while ((p = memchr(p, eol_marker, (e-p)))); |
} while ((p = memchr(p, eol_marker, (e-p)))); |
} |
} |
Line 849 PHP_FUNCTION(tempnam)
|
Line 805 PHP_FUNCTION(tempnam)
|
char *p; |
char *p; |
int fd; |
int fd; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &dir, &dir_len, &prefix, &prefix_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps", &dir, &dir_len, &prefix, &prefix_len) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(dir) != dir_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (strlen(prefix) != prefix_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (PG(safe_mode) &&(!php_checkuid(dir, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (php_check_open_basedir(dir TSRMLS_CC)) { |
if (php_check_open_basedir(dir TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
Line 915 PHP_NAMED_FUNCTION(php_if_fopen)
|
Line 859 PHP_NAMED_FUNCTION(php_if_fopen)
|
php_stream *stream; |
php_stream *stream; |
php_stream_context *context = NULL; |
php_stream_context *context = NULL; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|br", &filename, &filename_len, &mode, &mode_len, &use_include_path, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|br", &filename, &filename_len, &mode, &mode_len, &use_include_path, &zcontext) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
|
|
stream = php_stream_open_wrapper_ex(filename, mode, (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); | stream = php_stream_open_wrapper_ex(filename, mode, (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, context); |
|
|
if (stream == NULL) { |
if (stream == NULL) { |
RETURN_FALSE; |
RETURN_FALSE; |
Line 954 PHPAPI PHP_FUNCTION(fclose)
|
Line 894 PHPAPI PHP_FUNCTION(fclose)
|
} |
} |
|
|
if (!stream->is_persistent) { |
if (!stream->is_persistent) { |
zend_list_delete(stream->rsrc_id); | php_stream_close(stream); |
} else { |
} else { |
php_stream_pclose(stream); |
php_stream_pclose(stream); |
} |
} |
Line 971 PHP_FUNCTION(popen)
|
Line 911 PHP_FUNCTION(popen)
|
int command_len, mode_len; |
int command_len, mode_len; |
FILE *fp; |
FILE *fp; |
php_stream *stream; |
php_stream *stream; |
char *posix_mode, *b, *buf = 0, *tmp; | char *posix_mode; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &command, &command_len, &mode, &mode_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps", &command, &command_len, &mode, &mode_len) == FAILURE) { |
return; |
return; |
} |
} |
|
|
Line 986 PHP_FUNCTION(popen)
|
Line 926 PHP_FUNCTION(popen)
|
} |
} |
} |
} |
#endif |
#endif |
if (PG(safe_mode)){ |
|
b = strchr(command, ' '); |
|
if (!b) { |
|
b = strrchr(command, '/'); |
|
} else { |
|
char *c; |
|
|
|
c = command; | fp = VCWD_POPEN(command, posix_mode); |
while((*b != '/') && (b != c)) { | if (!fp) { |
b--; | php_error_docref2(NULL TSRMLS_CC, command, posix_mode, E_WARNING, "%s", strerror(errno)); |
} | efree(posix_mode); |
if (b == c) { | RETURN_FALSE; |
b = NULL; | |
} | |
} | |
| |
if (b) { | |
spprintf(&buf, 0, "%s%s", PG(safe_mode_exec_dir), b); | |
} else { | |
spprintf(&buf, 0, "%s/%s", PG(safe_mode_exec_dir), command); | |
} | |
| |
tmp = php_escape_shell_cmd(buf); | |
fp = VCWD_POPEN(tmp, posix_mode); | |
efree(tmp); | |
| |
if (!fp) { | |
php_error_docref2(NULL TSRMLS_CC, buf, posix_mode, E_WARNING, "%s", strerror(errno)); | |
efree(posix_mode); | |
efree(buf); | |
RETURN_FALSE; | |
} | |
| |
efree(buf); | |
| |
} else { | |
fp = VCWD_POPEN(command, posix_mode); | |
if (!fp) { | |
php_error_docref2(NULL TSRMLS_CC, command, posix_mode, E_WARNING, "%s", strerror(errno)); | |
efree(posix_mode); | |
RETURN_FALSE; | |
} | |
} |
} |
|
|
stream = php_stream_fopen_from_pipe(fp, mode); |
stream = php_stream_fopen_from_pipe(fp, mode); |
|
|
if (stream == NULL) { |
if (stream == NULL) { |
Line 1116 PHPAPI PHP_FUNCTION(fgets)
|
Line 1021 PHPAPI PHP_FUNCTION(fgets)
|
} |
} |
} |
} |
|
|
if (PG(magic_quotes_runtime)) { | ZVAL_STRINGL(return_value, buf, line_len, 0); |
Z_STRVAL_P(return_value) = php_addslashes(buf, line_len, &Z_STRLEN_P(return_value), 1 TSRMLS_CC); | /* resize buffer if it's much larger than the result. |
Z_TYPE_P(return_value) = IS_STRING; | * Only needed if the user requested a buffer size. */ |
} else { | if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) { |
ZVAL_STRINGL(return_value, buf, line_len, 0); | Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1); |
/* resize buffer if it's much larger than the result. | |
* Only needed if the user requested a buffer size. */ | |
if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) { | |
Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1); | |
} | |
} |
} |
return; |
return; |
|
|
Line 1286 PHPAPI PHP_FUNCTION(fwrite)
|
Line 1186 PHPAPI PHP_FUNCTION(fwrite)
|
|
|
PHP_STREAM_TO_ZVAL(stream, &arg1); |
PHP_STREAM_TO_ZVAL(stream, &arg1); |
|
|
if (PG(magic_quotes_runtime)) { |
|
buffer = estrndup(arg2, num_bytes); |
|
php_stripslashes(buffer, &num_bytes TSRMLS_CC); |
|
} |
|
|
|
ret = php_stream_write(stream, buffer ? buffer : arg2, num_bytes); |
ret = php_stream_write(stream, buffer ? buffer : arg2, num_bytes); |
if (buffer) { |
if (buffer) { |
efree(buffer); |
efree(buffer); |
Line 1390 PHPAPI int php_mkdir_ex(char *dir, long mode, int opti
|
Line 1285 PHPAPI int php_mkdir_ex(char *dir, long mode, int opti
|
{ |
{ |
int ret; |
int ret; |
|
|
if (PG(safe_mode) && (!php_checkuid(dir, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { |
|
return -1; |
|
} |
|
|
|
if (php_check_open_basedir(dir TSRMLS_CC)) { |
if (php_check_open_basedir(dir TSRMLS_CC)) { |
return -1; |
return -1; |
} |
} |
Line 1422 PHP_FUNCTION(mkdir)
|
Line 1313 PHP_FUNCTION(mkdir)
|
zend_bool recursive = 0; |
zend_bool recursive = 0; |
php_stream_context *context; |
php_stream_context *context; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lbr", &dir, &dir_len, &mode, &recursive, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|lbr", &dir, &dir_len, &mode, &recursive, &zcontext) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(dir) != dir_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
|
|
RETURN_BOOL(php_stream_mkdir(dir, mode, (recursive ? PHP_STREAM_MKDIR_RECURSIVE : 0) | REPORT_ERRORS, context)); |
RETURN_BOOL(php_stream_mkdir(dir, mode, (recursive ? PHP_STREAM_MKDIR_RECURSIVE : 0) | REPORT_ERRORS, context)); |
Line 1449 PHP_FUNCTION(rmdir)
|
Line 1336 PHP_FUNCTION(rmdir)
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(dir) != dir_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
|
|
RETURN_BOOL(php_stream_rmdir(dir, REPORT_ERRORS, context)); |
RETURN_BOOL(php_stream_rmdir(dir, REPORT_ERRORS, context)); |
Line 1471 PHP_FUNCTION(readfile)
|
Line 1354 PHP_FUNCTION(readfile)
|
php_stream *stream; |
php_stream *stream; |
php_stream_context *context = NULL; |
php_stream_context *context = NULL; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!", &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|br!", &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
|
|
stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); | stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, context); |
if (stream) { |
if (stream) { |
size = php_stream_passthru(stream); |
size = php_stream_passthru(stream); |
php_stream_close(stream); |
php_stream_close(stream); |
Line 1548 PHP_FUNCTION(rename)
|
Line 1427 PHP_FUNCTION(rename)
|
php_stream_wrapper *wrapper; |
php_stream_wrapper *wrapper; |
php_stream_context *context; |
php_stream_context *context; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|r", &old_name, &old_name_len, &new_name, &new_name_len, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp|r", &old_name, &old_name_len, &new_name, &new_name_len, &zcontext) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(old_name) != old_name_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (strlen(new_name) != new_name_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0 TSRMLS_CC); |
wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0 TSRMLS_CC); |
|
|
if (!wrapper || !wrapper->wops) { |
if (!wrapper || !wrapper->wops) { |
Line 1593 PHP_FUNCTION(unlink)
|
Line 1464 PHP_FUNCTION(unlink)
|
zval *zcontext = NULL; |
zval *zcontext = NULL; |
php_stream_context *context = NULL; |
php_stream_context *context = NULL; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &filename, &filename_len, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|r", &filename, &filename_len, &zcontext) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
|
|
wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); |
wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); |
Line 1614 PHP_FUNCTION(unlink)
|
Line 1481 PHP_FUNCTION(unlink)
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s does not allow unlinking", wrapper->wops->label ? wrapper->wops->label : "Wrapper"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s does not allow unlinking", wrapper->wops->label ? wrapper->wops->label : "Wrapper"); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
RETURN_BOOL(wrapper->wops->unlink(wrapper, filename, ENFORCE_SAFE_MODE | REPORT_ERRORS, context TSRMLS_CC)); | RETURN_BOOL(wrapper->wops->unlink(wrapper, filename, REPORT_ERRORS, context TSRMLS_CC)); |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 1733 PHP_FUNCTION(copy)
|
Line 1600 PHP_FUNCTION(copy)
|
zval *zcontext = NULL; |
zval *zcontext = NULL; |
php_stream_context *context; |
php_stream_context *context; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|r", &source, &source_len, &target, &target_len, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp|r", &source, &source_len, &target, &target_len, &zcontext) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(source) != source_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (strlen(target) != target_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (PG(safe_mode) &&(!php_checkuid(source, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (php_check_open_basedir(source TSRMLS_CC)) { |
if (php_check_open_basedir(source TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
Line 1767 PHP_FUNCTION(copy)
|
Line 1622 PHP_FUNCTION(copy)
|
*/ |
*/ |
PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC) |
PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC) |
{ |
{ |
return php_copy_file_ctx(src, dest, ENFORCE_SAFE_MODE, NULL TSRMLS_CC); | return php_copy_file_ctx(src, dest, 0, NULL TSRMLS_CC); |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
/* {{{ php_copy_file_ex |
/* {{{ php_copy_file_ex |
*/ |
*/ |
PHPAPI int php_copy_file_ex(char *src, char *dest, int src_chk TSRMLS_DC) | PHPAPI int php_copy_file_ex(char *src, char *dest, int src_flg TSRMLS_DC) |
{ |
{ |
return php_copy_file_ctx(src, dest, ENFORCE_SAFE_MODE, NULL TSRMLS_CC); | return php_copy_file_ctx(src, dest, 0, NULL TSRMLS_CC); |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
/* {{{ php_copy_file_ctx |
/* {{{ php_copy_file_ctx |
*/ |
*/ |
PHPAPI int php_copy_file_ctx(char *src, char *dest, int src_chk, php_stream_context *context TSRMLS_DC) | PHPAPI int php_copy_file_ctx(char *src, char *dest, int src_flg, php_stream_context *ctx TSRMLS_DC) |
{ |
{ |
php_stream *srcstream = NULL, *deststream = NULL; |
php_stream *srcstream = NULL, *deststream = NULL; |
int ret = FAILURE; |
int ret = FAILURE; |
php_stream_statbuf src_s, dest_s; |
php_stream_statbuf src_s, dest_s; |
|
|
switch (php_stream_stat_path_ex(src, 0, &src_s, context)) { | switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) { |
case -1: |
case -1: |
/* non-statable stream */ |
/* non-statable stream */ |
goto safe_to_copy; |
goto safe_to_copy; |
Line 1802 PHPAPI int php_copy_file_ctx(char *src, char *dest, in
|
Line 1657 PHPAPI int php_copy_file_ctx(char *src, char *dest, in
|
return FAILURE; |
return FAILURE; |
} |
} |
|
|
switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET, &dest_s, context)) { | switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET | PHP_STREAM_URL_STAT_NOCACHE, &dest_s, ctx)) { |
case -1: |
case -1: |
/* non-statable stream */ |
/* non-statable stream */ |
goto safe_to_copy; |
goto safe_to_copy; |
Line 1852 no_stat:
|
Line 1707 no_stat:
|
} |
} |
safe_to_copy: |
safe_to_copy: |
|
|
srcstream = php_stream_open_wrapper_ex(src, "rb", src_chk | REPORT_ERRORS, NULL, context); | srcstream = php_stream_open_wrapper_ex(src, "rb", src_flg | REPORT_ERRORS, NULL, ctx); |
|
|
if (!srcstream) { |
if (!srcstream) { |
return ret; |
return ret; |
} |
} |
|
|
deststream = php_stream_open_wrapper_ex(dest, "wb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); | deststream = php_stream_open_wrapper_ex(dest, "wb", REPORT_ERRORS, NULL, ctx); |
|
|
if (srcstream && deststream) { |
if (srcstream && deststream) { |
ret = php_stream_copy_to_stream_ex(srcstream, deststream, PHP_STREAM_COPY_ALL, NULL); |
ret = php_stream_copy_to_stream_ex(srcstream, deststream, PHP_STREAM_COPY_ALL, NULL); |
Line 1897 PHPAPI PHP_FUNCTION(fread)
|
Line 1752 PHPAPI PHP_FUNCTION(fread)
|
|
|
/* needed because recv/read/gzread doesnt put a null at the end*/ |
/* needed because recv/read/gzread doesnt put a null at the end*/ |
Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0; |
Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0; |
|
|
if (PG(magic_quotes_runtime)) { |
|
Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_P(return_value), |
|
Z_STRLEN_P(return_value), &Z_STRLEN_P(return_value), 1 TSRMLS_CC); |
|
} |
|
Z_TYPE_P(return_value) = IS_STRING; |
Z_TYPE_P(return_value) = IS_STRING; |
} |
} |
/* }}} */ |
/* }}} */ |
Line 1917 static const char *php_fgetcsv_lookup_trailing_spaces(
|
Line 1767 static const char *php_fgetcsv_lookup_trailing_spaces(
|
case -2: |
case -2: |
case -1: |
case -1: |
inc_len = 1; |
inc_len = 1; |
php_mblen(NULL, 0); | php_ignore_value(php_mblen(NULL, 0)); |
break; |
break; |
case 0: |
case 0: |
goto quit_loop; |
goto quit_loop; |
Line 1954 PHP_FUNCTION(fputcsv)
|
Line 1804 PHP_FUNCTION(fputcsv)
|
char enclosure = '"'; /* allow this to be set as parameter */ |
char enclosure = '"'; /* allow this to be set as parameter */ |
const char escape_char = '\\'; |
const char escape_char = '\\'; |
php_stream *stream; |
php_stream *stream; |
|
zval *fp = NULL, *fields = NULL; |
int ret; |
int ret; |
zval *fp = NULL, *fields = NULL, **field_tmp = NULL, field; |
|
char *delimiter_str = NULL, *enclosure_str = NULL; |
char *delimiter_str = NULL, *enclosure_str = NULL; |
int delimiter_str_len = 0, enclosure_str_len = 0; |
int delimiter_str_len = 0, enclosure_str_len = 0; |
HashPosition pos; |
|
int count, i = 0; |
|
smart_str csvline = {0}; |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|ss", |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|ss", |
&fp, &fields, &delimiter_str, &delimiter_str_len, |
&fp, &fields, &delimiter_str, &delimiter_str_len, |
Line 1994 PHP_FUNCTION(fputcsv)
|
Line 1841 PHP_FUNCTION(fputcsv)
|
|
|
PHP_STREAM_TO_ZVAL(stream, &fp); |
PHP_STREAM_TO_ZVAL(stream, &fp); |
|
|
|
ret = php_fputcsv(stream, fields, delimiter, enclosure, escape_char TSRMLS_CC); |
|
RETURN_LONG(ret); |
|
} |
|
/* }}} */ |
|
|
|
/* {{{ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC) */ |
|
PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC) |
|
{ |
|
int count, i = 0, ret; |
|
zval **field_tmp = NULL, field; |
|
smart_str csvline = {0}; |
|
HashPosition pos; |
|
|
count = zend_hash_num_elements(Z_ARRVAL_P(fields)); |
count = zend_hash_num_elements(Z_ARRVAL_P(fields)); |
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(fields), &pos); |
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(fields), &pos); |
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(fields), (void **) &field_tmp, &pos) == SUCCESS) { |
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(fields), (void **) &field_tmp, &pos) == SUCCESS) { |
Line 2047 PHP_FUNCTION(fputcsv)
|
Line 1907 PHP_FUNCTION(fputcsv)
|
smart_str_appendc(&csvline, '\n'); |
smart_str_appendc(&csvline, '\n'); |
smart_str_0(&csvline); |
smart_str_0(&csvline); |
|
|
if (!PG(magic_quotes_runtime)) { | ret = php_stream_write(stream, csvline.c, csvline.len); |
ret = php_stream_write(stream, csvline.c, csvline.len); | |
} else { | |
char *buffer = estrndup(csvline.c, csvline.len); | |
int len = csvline.len; | |
php_stripslashes(buffer, &len TSRMLS_CC); | |
ret = php_stream_write(stream, buffer, len); | |
efree(buffer); | |
} | |
|
|
smart_str_free(&csvline); |
smart_str_free(&csvline); |
|
|
RETURN_LONG(ret); | return ret; |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 2171 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
Line 2023 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
zend_bool first_field = 1; |
zend_bool first_field = 1; |
|
|
/* initialize internal state */ |
/* initialize internal state */ |
php_mblen(NULL, 0); | php_ignore_value(php_mblen(NULL, 0)); |
|
|
/* Now into new section that parses buf for delimiter/enclosure fields */ |
/* Now into new section that parses buf for delimiter/enclosure fields */ |
|
|
Line 2196 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
Line 2048 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
char *comp_end, *hunk_begin; |
char *comp_end, *hunk_begin; |
|
|
tptr = temp; |
tptr = temp; |
|
|
inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0); |
inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0); |
if (inc_len == 1) { |
if (inc_len == 1) { |
char *tmp = bptr; |
char *tmp = bptr; |
Line 2285 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
Line 2138 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
|
|
case -2: |
case -2: |
case -1: |
case -1: |
php_mblen(NULL, 0); | php_ignore_value(php_mblen(NULL, 0)); |
/* break is omitted intentionally */ |
/* break is omitted intentionally */ |
case 1: |
case 1: |
/* we need to determine if the enclosure is |
/* we need to determine if the enclosure is |
Line 2353 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
Line 2206 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
case -2: |
case -2: |
case -1: |
case -1: |
inc_len = 1; |
inc_len = 1; |
php_mblen(NULL, 0); | php_ignore_value(php_mblen(NULL, 0)); |
/* break is omitted intentionally */ |
/* break is omitted intentionally */ |
case 1: |
case 1: |
if (*bptr == delimiter) { |
if (*bptr == delimiter) { |
Line 2384 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
Line 2237 PHPAPI void php_fgetcsv(php_stream *stream, char delim
|
case -2: |
case -2: |
case -1: |
case -1: |
inc_len = 1; |
inc_len = 1; |
php_mblen(NULL, 0); | php_ignore_value(php_mblen(NULL, 0)); |
/* break is omitted intentionally */ |
/* break is omitted intentionally */ |
case 1: |
case 1: |
if (*bptr == delimiter) { |
if (*bptr == delimiter) { |
Line 2429 PHP_FUNCTION(realpath)
|
Line 2282 PHP_FUNCTION(realpath)
|
int filename_len; |
int filename_len; |
char resolved_path_buff[MAXPATHLEN]; |
char resolved_path_buff[MAXPATHLEN]; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (VCWD_REALPATH(filename, resolved_path_buff)) { |
if (VCWD_REALPATH(filename, resolved_path_buff)) { |
if (PG(safe_mode) && (!php_checkuid(resolved_path_buff, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (php_check_open_basedir(resolved_path_buff TSRMLS_CC)) { |
if (php_check_open_basedir(resolved_path_buff TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
Line 2575 PHP_FUNCTION(fnmatch)
|
Line 2420 PHP_FUNCTION(fnmatch)
|
int pattern_len, filename_len; |
int pattern_len, filename_len; |
long flags = 0; |
long flags = 0; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &pattern, &pattern_len, &filename, &filename_len, &flags) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp|l", &pattern, &pattern_len, &filename, &filename_len, &flags) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(pattern) != pattern_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (filename_len >= MAXPATHLEN) { |
if (filename_len >= MAXPATHLEN) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename exceeds the maximum allowed length of %d characters", MAXPATHLEN); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename exceeds the maximum allowed length of %d characters", MAXPATHLEN); |
RETURN_FALSE; |
RETURN_FALSE; |