diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/SAPI.c | 120 | ||||
-rw-r--r-- | main/SAPI.h | 14 | ||||
-rw-r--r-- | main/fopen_wrappers.c | 8 | ||||
-rw-r--r-- | main/main.c | 11 | ||||
-rw-r--r-- | main/php.h | 6 | ||||
-rw-r--r-- | main/php_content_types.c | 23 | ||||
-rw-r--r-- | main/php_globals.h | 1 | ||||
-rw-r--r-- | main/php_open_temporary_file.c | 10 | ||||
-rw-r--r-- | main/php_stdint.h | 206 | ||||
-rw-r--r-- | main/php_streams.h | 46 | ||||
-rw-r--r-- | main/php_variables.c | 131 | ||||
-rw-r--r-- | main/php_version.h | 8 | ||||
-rw-r--r-- | main/rfc1867.c | 48 | ||||
-rw-r--r-- | main/streams/glob_wrapper.c | 10 | ||||
-rw-r--r-- | main/streams/memory.c | 8 | ||||
-rw-r--r-- | main/streams/php_stream_plain_wrapper.h | 2 | ||||
-rw-r--r-- | main/streams/php_stream_transport.h | 22 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 23 | ||||
-rw-r--r-- | main/streams/streams.c | 62 | ||||
-rw-r--r-- | main/streams/transports.c | 10 | ||||
-rw-r--r-- | main/streams/userspace.c | 38 | ||||
-rw-r--r-- | main/streams/xp_socket.c | 8 |
22 files changed, 560 insertions, 255 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index dcb2da629a..c9ba5d5dce 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -91,8 +91,6 @@ SAPI_API void sapi_startup(sapi_module_struct *sf) sapi_globals_ctor(&sapi_globals); #endif - virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */ - #ifdef PHP_WIN32 tsrm_win32_startup(); #endif @@ -110,8 +108,6 @@ SAPI_API void sapi_shutdown(void) reentrancy_shutdown(); - virtual_cwd_shutdown(); - #ifdef PHP_WIN32 tsrm_win32_shutdown(); #endif @@ -180,10 +176,6 @@ SAPI_API void sapi_handle_post(void *arg TSRMLS_DC) { if (SG(request_info).post_entry && SG(request_info).content_type_dup) { SG(request_info).post_entry->post_handler(SG(request_info).content_type_dup, arg TSRMLS_CC); - if (SG(request_info).post_data) { - efree(SG(request_info).post_data); - SG(request_info).post_data = NULL; - } efree(SG(request_info).content_type_dup); SG(request_info).content_type_dup = NULL; } @@ -249,39 +241,63 @@ static void sapi_read_post_data(TSRMLS_D) } } - -SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) +SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC) { int read_bytes; - int allocated_bytes=SAPI_POST_BLOCK_SIZE+1; + if (!sapi_module.read_post) { + return -1; + } + + read_bytes = sapi_module.read_post(buffer, buflen TSRMLS_CC); + + if (read_bytes > 0) { + /* gogo */ + SG(read_post_bytes) += read_bytes; + } + if (read_bytes < buflen) { + /* done */ + SG(post_read) = 1; + } + + return read_bytes; +} + +SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) +{ if ((SG(post_max_size) > 0) && (SG(request_info).content_length > SG(post_max_size))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size)); return; } - SG(request_info).post_data = emalloc(allocated_bytes); - for (;;) { - read_bytes = sapi_module.read_post(SG(request_info).post_data+SG(read_post_bytes), SAPI_POST_BLOCK_SIZE TSRMLS_CC); - if (read_bytes<=0) { - break; - } - SG(read_post_bytes) += read_bytes; - if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size)); - break; - } - if (read_bytes < SAPI_POST_BLOCK_SIZE) { - break; - } - if (SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE >= allocated_bytes) { - allocated_bytes = SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE+1; - SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes); + + SG(request_info).request_body = php_stream_temp_create(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE); + + if (sapi_module.read_post) { + int read_bytes; + + for (;;) { + char buffer[SAPI_POST_BLOCK_SIZE]; + + read_bytes = sapi_read_post_block(buffer, SAPI_POST_BLOCK_SIZE TSRMLS_CC); + + if (read_bytes > 0) { + php_stream_write(SG(request_info).request_body, buffer, read_bytes); + } + + if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size)); + break; + } + + if (read_bytes < SAPI_POST_BLOCK_SIZE) { + /* done */ + break; + } } + php_stream_rewind(SG(request_info).request_body); } - SG(request_info).post_data[SG(read_post_bytes)] = 0; /* terminating NULL */ - SG(request_info).post_data_length = SG(read_post_bytes); } @@ -387,8 +403,7 @@ SAPI_API void sapi_activate_headers_only(TSRMLS_D) SG(sapi_headers).http_status_line = NULL; SG(sapi_headers).mimetype = NULL; SG(read_post_bytes) = 0; - SG(request_info).post_data = NULL; - SG(request_info).raw_post_data = NULL; + SG(request_info).request_body = NULL; SG(request_info).current_user = NULL; SG(request_info).current_user_length = 0; SG(request_info).no_headers = 0; @@ -433,8 +448,7 @@ SAPI_API void sapi_activate(TSRMLS_D) SG(callback_run) = 0; SG(callback_func) = NULL; SG(read_post_bytes) = 0; - SG(request_info).post_data = NULL; - SG(request_info).raw_post_data = NULL; + SG(request_info).request_body = NULL; SG(request_info).current_user = NULL; SG(request_info).current_user_length = 0; SG(request_info).no_headers = 0; @@ -452,20 +466,13 @@ SAPI_API void sapi_activate(TSRMLS_D) /* Handle request method */ if (SG(server_context)) { - if (PG(enable_post_data_reading) && SG(request_info).request_method) { - if (SG(request_info).content_type && !strcmp(SG(request_info).request_method, "POST")) { - /* HTTP POST may contain form data to be processed into variables - * depending on given content type */ - sapi_read_post_data(TSRMLS_C); - } else { - /* Any other method with content payload will fill $HTTP_RAW_POST_DATA - * if it is enabled by always_populate_raw_post_data. - * It's up to the webserver to decide whether to allow a method or not. */ - SG(request_info).content_type_dup = NULL; - if (sapi_module.default_post_reader) { - sapi_module.default_post_reader(TSRMLS_C); - } - } + if (PG(enable_post_data_reading) + && SG(request_info).content_type + && SG(request_info).request_method + && !strcmp(SG(request_info).request_method, "POST")) { + /* HTTP POST may contain form data to be processed into variables + * depending on given content type */ + sapi_read_post_data(TSRMLS_C); } else { SG(request_info).content_type_dup = NULL; } @@ -494,22 +501,19 @@ static void sapi_send_headers_free(TSRMLS_D) SAPI_API void sapi_deactivate(TSRMLS_D) { zend_llist_destroy(&SG(sapi_headers).headers); - if (SG(request_info).post_data) { - efree(SG(request_info).post_data); - } else if (SG(server_context)) { - if(sapi_module.read_post) { + if (SG(request_info).request_body) { + SG(request_info).request_body = NULL; + } else if (SG(server_context)) { + if (!SG(post_read)) { /* make sure we've consumed all request input data */ char dummy[SAPI_POST_BLOCK_SIZE]; int read_bytes; - while((read_bytes = sapi_module.read_post(dummy, sizeof(dummy)-1 TSRMLS_CC)) > 0) { - SG(read_post_bytes) += read_bytes; - } + do { + read_bytes = sapi_read_post_block(dummy, SAPI_POST_BLOCK_SIZE TSRMLS_CC); + } while (SAPI_POST_BLOCK_SIZE == read_bytes); } } - if (SG(request_info).raw_post_data) { - efree(SG(request_info).raw_post_data); - } if (SG(request_info).auth_user) { efree(SG(request_info).auth_user); } diff --git a/main/SAPI.h b/main/SAPI.h index 92b7329dbc..928fca95da 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -27,12 +27,12 @@ #include "zend_operators.h" #ifdef PHP_WIN32 #include "win95nt.h" +#include "win32/php_stdint.h" #endif #include <sys/stat.h> #define SAPI_OPTION_NO_CHDIR 1 - -#define SAPI_POST_BLOCK_SIZE 4000 +#define SAPI_POST_BLOCK_SIZE 0x4000 #ifdef PHP_WIN32 # ifdef SAPI_EXPORTS @@ -79,14 +79,15 @@ END_EXTERN_C() typedef struct { const char *request_method; char *query_string; - char *post_data, *raw_post_data; char *cookie_data; long content_length; - uint post_data_length, raw_post_data_length; char *path_translated; char *request_uri; + /* Do not use request_body directly, but the php://input stream wrapper instead */ + struct _php_stream *request_body; + const char *content_type; zend_bool headers_only; @@ -119,7 +120,8 @@ typedef struct _sapi_globals_struct { void *server_context; sapi_request_info request_info; sapi_headers_struct sapi_headers; - int read_post_bytes; + int64_t read_post_bytes; + unsigned char post_read; unsigned char headers_sent; struct stat global_stat; char *default_mimetype; @@ -188,7 +190,7 @@ SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bo SAPI_API int sapi_send_headers(TSRMLS_D); SAPI_API void sapi_free_header(sapi_header_struct *sapi_header); SAPI_API void sapi_handle_post(void *arg TSRMLS_DC); - +SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC); SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry TSRMLS_DC); SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC); SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC); diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 9b8645a061..6722798598 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -475,7 +475,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c char resolved_path[MAXPATHLEN]; char trypath[MAXPATHLEN]; const char *ptr, *end, *p; - char *actual_path; + const char *actual_path; php_stream_wrapper *wrapper; if (!filename || CHECK_NULL_PATH(filename, filename_length)) { @@ -791,11 +791,11 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co } } - new_state.cwd = strdup(cwd); + new_state.cwd = estrdup(cwd); new_state.cwd_length = strlen(cwd); if (virtual_file_ex(&new_state, filepath, NULL, realpath_mode TSRMLS_CC)) { - free(new_state.cwd); + efree(new_state.cwd); return NULL; } @@ -806,7 +806,7 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co } else { real_path = estrndup(new_state.cwd, new_state.cwd_length); } - free(new_state.cwd); + efree(new_state.cwd); return real_path; } diff --git a/main/main.c b/main/main.c index ce31cae432..04338e76c7 100644 --- a/main/main.c +++ b/main/main.c @@ -562,7 +562,6 @@ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("enable_post_data_reading", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, enable_post_data_reading, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals) STD_PHP_INI_ENTRY("realpath_cache_size", "16K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals) STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals) @@ -1340,7 +1339,7 @@ PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *h handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read; handle->handle.stream.fsizer = php_zend_stream_fsizer; handle->handle.stream.isatty = 0; - /* can we mmap immeadiately? */ + /* can we mmap immediately? */ memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap)); len = php_zend_stream_fsizer(stream TSRMLS_CC); if (len != 0 @@ -1817,6 +1816,9 @@ void php_request_shutdown(void *dummy) sapi_deactivate(TSRMLS_C); } zend_end_try(); + /* 9.5 free virtual CWD memory */ + virtual_cwd_deactivate(TSRMLS_C); + /* 10. Destroy stream hashes */ zend_try { php_shutdown_stream_hashes(TSRMLS_C); @@ -2209,7 +2211,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod zend_set_utility_values(&zuv); php_startup_sapi_content_types(TSRMLS_C); - /* startup extensions staticly compiled in */ + /* startup extensions statically compiled in */ if (php_register_internal_extensions_func(TSRMLS_C) == FAILURE) { php_printf("Unable to start builtin modules\n"); return FAILURE; @@ -2261,9 +2263,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod } #endif -#ifdef ZTS zend_post_startup(TSRMLS_C); -#endif module_initialized = 1; @@ -2333,6 +2333,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod shutdown_memory_manager(1, 0 TSRMLS_CC); zend_interned_strings_snapshot(TSRMLS_C); + virtual_cwd_activate(TSRMLS_C); /* we're done */ return retval; diff --git a/main/php.h b/main/php.h index 7c1f8fd0c7..ed8a2bb08e 100644 --- a/main/php.h +++ b/main/php.h @@ -26,7 +26,7 @@ #include <dmalloc.h> #endif -#define PHP_API_VERSION 20121113 +#define PHP_API_VERSION 20131106 #define PHP_HAVE_STREAMS #define YYDEBUG 0 @@ -180,6 +180,8 @@ typedef unsigned int socklen_t; # endif #endif +#include "php_stdint.h" + #include "zend_hash.h" #include "zend_alloc.h" #include "zend_stack.h" @@ -398,7 +400,7 @@ END_EXTERN_C() /* Virtual current working directory support */ -#include "tsrm_virtual_cwd.h" +#include "zend_virtual_cwd.h" #include "zend_constants.h" diff --git a/main/php_content_types.c b/main/php_content_types.c index c4433978ed..3346efc50e 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -37,34 +37,11 @@ static sapi_post_entry php_post_entries[] = { */ SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) { - char *data; - int length; - - /* $HTTP_RAW_POST_DATA registration */ if (!strcmp(SG(request_info).request_method, "POST")) { if (NULL == SG(request_info).post_entry) { /* no post handler registered, so we just swallow the data */ sapi_read_standard_form_data(TSRMLS_C); } - - /* For unknown content types we create HTTP_RAW_POST_DATA even if always_populate_raw_post_data off, - * this is in-effecient, but we need to keep doing it for BC reasons (for now) */ - if ((PG(always_populate_raw_post_data) || NULL == SG(request_info).post_entry) && SG(request_info).post_data) { - length = SG(request_info).post_data_length; - data = estrndup(SG(request_info).post_data, length); - SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, length); - } - } - - /* for php://input stream: - some post handlers modify the content of request_info.post_data - so for now we need a copy for the php://input stream - in the long run post handlers should be changed to not touch - request_info.post_data for memory preservation reasons - */ - if (SG(request_info).post_data) { - SG(request_info).raw_post_data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length); - SG(request_info).raw_post_data_length = SG(request_info).post_data_length; } } /* }}} */ diff --git a/main/php_globals.h b/main/php_globals.h index 256765d665..fa2fe3b232 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -131,7 +131,6 @@ struct _php_core_globals { zend_bool during_request_startup; zend_bool allow_url_fopen; zend_bool enable_post_data_reading; - zend_bool always_populate_raw_post_data; zend_bool report_zend_debug; int last_error_type; diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c index 054d497be6..8315297738 100644 --- a/main/php_open_temporary_file.c +++ b/main/php_open_temporary_file.c @@ -124,11 +124,11 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char ** cwd[0] = '\0'; } - new_state.cwd = strdup(cwd); + new_state.cwd = estrdup(cwd); new_state.cwd_length = strlen(cwd); if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)) { - free(new_state.cwd); + efree(new_state.cwd); return -1; } @@ -140,7 +140,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char ** if (spprintf(&opened_path, 0, "%s%s%sXXXXXX", new_state.cwd, trailing_slash, pfx) >= MAXPATHLEN) { efree(opened_path); - free(new_state.cwd); + efree(new_state.cwd); return -1; } @@ -151,7 +151,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char ** * which means that opening it will fail... */ if (VCWD_CHMOD(opened_path, 0600)) { efree(opened_path); - free(new_state.cwd); + efree(new_state.cwd); return -1; } fd = VCWD_OPEN_MODE(opened_path, open_flags, 0600); @@ -170,7 +170,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char ** } else { *opened_path_p = opened_path; } - free(new_state.cwd); + efree(new_state.cwd); return fd; } /* }}} */ diff --git a/main/php_stdint.h b/main/php_stdint.h new file mode 100644 index 0000000000..87edb0fde0 --- /dev/null +++ b/main/php_stdint.h @@ -0,0 +1,206 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | 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 | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Michael Wallner <mike@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHP_STDINT_H +#define PHP_STDINT_H + +#if defined(_MSC_VER) +/* Make sure the regular stdint.h wasn't included already and prevent it to be + included afterwards. Though if some other library needs some stuff from + stdint.h included afterwards and misses it, we'd have to extend ours. On + the other hand, if stdint.h was included before, some conflicts might + happen so we'd likewise have to fix ours. */ +# if !defined(_STDINT) +# define _STDINT +# include "win32/php_stdint.h" +# endif +# define HAVE_INT8_T 1 +# define HAVE_UINT8_T 1 +# define HAVE_INT16_T 1 +# define HAVE_UINT16_T 1 +# define HAVE_INT32_T 1 +# define HAVE_UINT32_T 1 +# define HAVE_INT64_T 1 +# define HAVE_UINT64_T 1 +#else + +#include "php_config.h" + +#if HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +#if HAVE_INTTYPES_H +# include <inttypes.h> +#endif + +#if HAVE_STDINT_H +# include <stdint.h> +#endif + +#ifndef HAVE_INT8_T +# ifdef HAVE_INT8 +typedef int8 int8_t; +# else +typedef signed char int8_t; +# endif +#endif + +#ifndef INT8_C +# define INT8_C(c) c +#endif + +#ifndef HAVE_UINT8_T +# ifdef HAVE_UINT8 +typedef uint8 uint8_t +# elif HAVE_U_INT8_T +typedef u_int8_t uint8_t; +# else +typedef unsigned char uint8_t; +# endif +#endif + +#ifndef UINT8_C +# define UINT8_C(c) c +#endif + +#ifndef HAVE_INT16_T +# ifdef HAVE_INT16 +typedef int16 int16_t; +# elif SIZEOF_SHORT >= 2 +typedef signed short int16_t; +# else +# error "No suitable 16bit integer type found" +# endif +#endif + +#ifndef INT16_C +# define INT16_C(c) c +#endif + +#ifndef HAVE_UINT16_T +# ifdef HAVE_UINT16 +typedef uint16 uint16_t +# elif HAVE_U_INT16_T +typedef u_int16_t uint16_t; +# elif SIZEOF_SHORT >= 2 +typedef unsigned short uint16_t; +# else +# error "No suitable 16bit integer type found" +# endif +#endif + +#ifndef UINT16_C +# define UINT16_C(c) c +#endif + +#ifndef HAVE_INT32_T +# ifdef HAVE_INT32 +typedef int32 int32_t; +# elif SIZEOF_INT >= 4 +typedef int int32_t; +# elif SIZEOF_LONG >= 4 +typedef long int32_t; +# else +# error "No suitable 32bit integer type found" +# endif +#endif + +#ifndef INT32_C +# define INT32_C(c) c +#endif + +#ifndef HAVE_UINT32_T +# ifdef HAVE_UINT32 +typedef uint32 uint32_t +# elif HAVE_U_INT32_T +typedef u_int32_t uint32_t; +# elif SIZEOF_INT >= 4 +typedef unsigned int uint32_t; +# elif SIZEOF_LONG >= 4 +typedef unsigned long uint32_t; +# else +# error "No suitable 32bit integer type found" +# endif +#endif + +#ifndef UINT32_C +# define UINT32_C(c) c ## U +#endif + +#ifndef HAVE_INT64_T +# ifdef HAVE_INT64 +typedef int64 int64_t; +# elif SIZEOF_INT >= 8 +typedef int int64_t; +# elif SIZEOF_LONG >= 8 +typedef long int64_t; +# elif SIZEOF_LONG_LONG >= 8 +typedef long long int64_t; +# else +# error "No suitable 64bit integer type found" +# endif +#endif + +#ifndef INT64_C +# if SIZEOF_INT >= 8 +# define INT64_C(c) c +# elif SIZEOF_LONG >= 8 +# define INT64_C(c) c ## L +# elif SIZEOF_LONG_LONG >= 8 +# define INT64_C(c) c ## LL +# endif +#endif + +#ifndef HAVE_UINT64_T +# ifdef HAVE_UINT64 +typedef uint64 uint64_t +# elif HAVE_U_INT64_T +typedef u_int64_t uint64_t; +# elif SIZEOF_INT >= 8 +typedef unsigned int uint64_t; +# elif SIZEOF_LONG >= 8 +typedef unsigned long uint64_t; +# elif SIZEOF_LONG_LONG >= 8 +typedef unsigned long long uint64_t; +# else +# error "No suitable 64bit integer type found" +# endif +#endif + +#ifndef UINT64_C +# if SIZEOF_INT >= 8 +# define UINT64_C(c) c ## U +# elif SIZEOF_LONG >= 8 +# define UINT64_C(c) c ## UL +# elif SIZEOF_LONG_LONG >= 8 +# define UINT64_C(c) c ## ULL +# endif +#endif + +#endif /* !PHP_WIN32 */ +#endif /* PHP_STDINT_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_streams.h b/main/php_streams.h index 5acf942e43..c9732b4848 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -131,31 +131,31 @@ typedef struct _php_stream_ops { typedef struct _php_stream_wrapper_ops { /* open/create a wrapped stream */ - php_stream *(*stream_opener)(php_stream_wrapper *wrapper, char *filename, char *mode, + php_stream *(*stream_opener)(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); /* close/destroy a wrapped stream */ int (*stream_closer)(php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC); /* stat a wrapped stream */ int (*stream_stat)(php_stream_wrapper *wrapper, php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC); /* stat a URL */ - int (*url_stat)(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); + int (*url_stat)(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); /* open a "directory" stream */ - php_stream *(*dir_opener)(php_stream_wrapper *wrapper, char *filename, char *mode, + php_stream *(*dir_opener)(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); const char *label; /* delete a file */ - int (*unlink)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); + int (*unlink)(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC); /* rename a file */ - int (*rename)(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC); + int (*rename)(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC); /* Create/Remove directory */ - int (*stream_mkdir)(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC); - int (*stream_rmdir)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); + int (*stream_mkdir)(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC); + int (*stream_rmdir)(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC); /* Metadata handling */ - int (*stream_metadata)(php_stream_wrapper *wrapper, char *url, int options, void *value, php_stream_context *context TSRMLS_DC); + int (*stream_metadata)(php_stream_wrapper *wrapper, const char *url, int options, void *value, php_stream_context *context TSRMLS_DC); } php_stream_wrapper_ops; struct _php_stream_wrapper { @@ -242,7 +242,7 @@ PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, END_EXTERN_C() #define php_stream_alloc(ops, thisptr, persistent_id, mode) _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC TSRMLS_CC) -#define php_stream_get_resource_id(stream) (stream)->rsrc_id +#define php_stream_get_resource_id(stream) ((php_stream *)(stream))->rsrc_id #if ZEND_DEBUG /* use this to tell the stream that it is OK if we don't explicitly close it */ # define php_stream_auto_cleanup(stream) { (stream)->__exposed++; } @@ -322,26 +322,26 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, #define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC) #define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC) -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC); +PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC); /* CAREFUL! this is equivalent to puts NOT fputs! */ -PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC); +PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC); #define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf) TSRMLS_CC) PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC); #define php_stream_stat(stream, ssb) _php_stream_stat((stream), (ssb) TSRMLS_CC) -PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); +PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); #define php_stream_stat_path(path, ssb) _php_stream_stat_path((path), 0, (ssb), NULL TSRMLS_CC) #define php_stream_stat_path_ex(path, flags, ssb, context) _php_stream_stat_path((path), (flags), (ssb), (context) TSRMLS_CC) -PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC); +PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context TSRMLS_DC); #define php_stream_mkdir(path, mode, options, context) _php_stream_mkdir(path, mode, options, context TSRMLS_CC) -PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC); +PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context TSRMLS_DC); #define php_stream_rmdir(path, options, context) _php_stream_rmdir(path, options, context TSRMLS_CC) -PHPAPI php_stream *_php_stream_opendir(char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC); +PHPAPI php_stream *_php_stream_opendir(const char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC); #define php_stream_opendir(path, options, context) _php_stream_opendir((path), (options), (context) STREAMS_CC TSRMLS_CC) PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent TSRMLS_DC); #define php_stream_readdir(dirstream, dirent) _php_stream_readdir((dirstream), (dirent) TSRMLS_CC) @@ -351,7 +351,7 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_ PHPAPI int php_stream_dirent_alphasort(const char **a, const char **b); PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b); -PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context, +PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags, php_stream_context *context, int (*compare) (const char **a, const char **b) TSRMLS_DC); #define php_stream_scandir(dirname, namelist, context, compare) _php_stream_scandir((dirname), (namelist), 0, (context), (compare) TSRMLS_CC) @@ -540,13 +540,13 @@ void php_shutdown_stream_hashes(TSRMLS_D); PHP_RSHUTDOWN_FUNCTION(streams); BEGIN_EXTERN_C() -PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC); -PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC); -PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC); -PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC); -PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); -PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC); -PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC); +PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC); +PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC); +PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC); +PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC); +PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); +PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC); +PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC); #define php_stream_open_wrapper(path, mode, options, opened) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC) #define php_stream_open_wrapper_ex(path, mode, options, opened, context) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC) diff --git a/main/php_variables.c b/main/php_variables.c index 7018eae57b..ab9aee3ae3 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -23,11 +23,15 @@ #include "php.h" #include "ext/standard/php_standard.h" #include "ext/standard/credits.h" +#include "ext/standard/php_smart_str.h" #include "php_variables.h" #include "php_globals.h" #include "php_content_types.h" #include "SAPI.h" #include "zend_globals.h" +#ifdef PHP_WIN32 +# include "win32/php_inttypes.h" +#endif /* for systems that need to override reading of environment variables */ void _php_import_environment_variables(zval *array_ptr TSRMLS_DC); @@ -228,44 +232,115 @@ plain_var: free_alloca(var_orig, use_heap); } +typedef struct post_var_data { + smart_str str; + char *ptr; + char *end; + uint64_t cnt; +} post_var_data_t; + +static zend_bool add_post_var(zval *arr, post_var_data_t *var, zend_bool eof TSRMLS_DC) +{ + char *ksep, *vsep; + size_t klen, vlen; + /* FIXME: string-size_t */ + unsigned int new_vlen; + + if (var->ptr >= var->end) { + return 0; + } + + vsep = memchr(var->ptr, '&', var->end - var->ptr); + if (!vsep) { + if (!eof) { + return 0; + } else { + vsep = var->end; + } + } + + ksep = memchr(var->ptr, '=', vsep - var->ptr); + if (ksep) { + *ksep = '\0'; + /* "foo=bar&" or "foo=&" */ + klen = ksep - var->ptr; + vlen = vsep - ++ksep; + } else { + ksep = ""; + /* "foo&" */ + klen = vsep - var->ptr; + vlen = 0; + } + + + php_url_decode(var->ptr, klen); + if (vlen) { + vlen = php_url_decode(ksep, vlen); + } + + if (sapi_module.input_filter(PARSE_POST, var->ptr, &ksep, vlen, &new_vlen TSRMLS_CC)) { + php_register_variable_safe(var->ptr, ksep, new_vlen, arr TSRMLS_CC); + } + + var->ptr = vsep + (vsep != var->end); + return 1; +} + +static inline int add_post_vars(zval *arr, post_var_data_t *vars, zend_bool eof TSRMLS_DC) +{ + uint64_t max_vars = PG(max_input_vars); + + vars->ptr = vars->str.c; + vars->end = vars->str.c + vars->str.len; + while (add_post_var(arr, vars, eof TSRMLS_CC)) { + if (++vars->cnt > max_vars) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Input variables exceeded %" PRIu64 ". " + "To increase the limit change max_input_vars in php.ini.", + max_vars); + return FAILURE; + } + } + + if (!eof) { + memmove(vars->str.c, vars->ptr, vars->str.len = vars->end - vars->ptr); + } + return SUCCESS; +} + SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler) { - char *var, *val, *e, *s, *p; - zval *array_ptr = (zval *) arg; - long count = 0; + zval *arr = (zval *) arg; + php_stream *s = SG(request_info).request_body; + post_var_data_t post_data; - if (SG(request_info).post_data == NULL) { - return; - } + if (s && SUCCESS == php_stream_rewind(s)) { + memset(&post_data, 0, sizeof(post_data)); - s = SG(request_info).post_data; - e = s + SG(request_info).post_data_length; + while (!php_stream_eof(s)) { + char buf[BUFSIZ] = {0}; + size_t len = php_stream_read(s, buf, BUFSIZ); - while (s < e && (p = memchr(s, '&', (e - s)))) { -last_value: - if ((val = memchr(s, '=', (p - s)))) { /* have a value */ - unsigned int val_len, new_val_len; + if (len && len != (size_t) -1) { + smart_str_appendl(&post_data.str, buf, len); - if (++count > PG(max_input_vars)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars)); - return; + if (SUCCESS != add_post_vars(arr, &post_data, 0 TSRMLS_CC)) { + if (post_data.str.c) { + efree(post_data.str.c); + } + return; + } } - var = s; - php_url_decode(var, (val - s)); - val++; - val_len = php_url_decode(val, (p - val)); - val = estrndup(val, val_len); - if (sapi_module.input_filter(PARSE_POST, var, &val, val_len, &new_val_len TSRMLS_CC)) { - php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC); + if (len != BUFSIZ){ + break; } - efree(val); } - s = p + 1; - } - if (s < e) { - p = e; - goto last_value; + + add_post_vars(arr, &post_data, 1 TSRMLS_CC); + if (post_data.str.c) { + efree(post_data.str.c); + } } } diff --git a/main/php_version.h b/main/php_version.h index 8d30a367d3..d48bf13c6f 100644 --- a/main/php_version.h +++ b/main/php_version.h @@ -1,8 +1,8 @@ /* automatically generated by configure */ /* edit configure.in to change version number */ #define PHP_MAJOR_VERSION 5 -#define PHP_MINOR_VERSION 5 -#define PHP_RELEASE_VERSION 8 +#define PHP_MINOR_VERSION 6 +#define PHP_RELEASE_VERSION 0 #define PHP_EXTRA_VERSION "-dev" -#define PHP_VERSION "5.5.8-dev" -#define PHP_VERSION_ID 50508 +#define PHP_VERSION "5.6.0-dev" +#define PHP_VERSION_ID 50600 diff --git a/main/rfc1867.c b/main/rfc1867.c index 7c208c368c..4adc25767d 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -34,6 +34,10 @@ #include "rfc1867.h" #include "ext/standard/php_string.h" +#if defined(PHP_WIN32) && !defined(HAVE_ATOLL) +# define atoll(s) _atoi64(s) +#endif + #define DEBUG_FILE_UPLOAD ZEND_DEBUG static int dummy_encoding_translation(TSRMLS_D) @@ -676,8 +680,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ { char *boundary, *s = NULL, *boundary_end = NULL, *start_arr = NULL, *array_index = NULL; char *temp_filename = NULL, *lbuf = NULL, *abuf = NULL; - int boundary_len = 0, total_bytes = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0; - int max_file_size = 0, skip_upload = 0, anonindex = 0, is_anonymous; + int boundary_len = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0; + int64_t total_bytes = 0, max_file_size = 0; + int skip_upload = 0, anonindex = 0, is_anonymous; zval *http_post_files = NULL; HashTable *uploaded_files = NULL; multipart_buffer *mbuff; @@ -898,7 +903,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } if (!strcasecmp(param, "MAX_FILE_SIZE")) { - max_file_size = atol(value); + max_file_size = atoll(value); } efree(param); @@ -1210,17 +1215,32 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ { zval file_size, error_type; + int size_overflow = 0; + char file_size_buf[65]; - error_type.value.lval = cancel_upload; - error_type.type = IS_LONG; + ZVAL_LONG(&error_type, cancel_upload); /* Add $foo[error] */ if (cancel_upload) { - file_size.value.lval = 0; - file_size.type = IS_LONG; + ZVAL_LONG(&file_size, 0); } else { - file_size.value.lval = total_bytes; - file_size.type = IS_LONG; + if (total_bytes > LONG_MAX) { +#ifdef PHP_WIN32 + if (_i64toa_s(total_bytes, file_size_buf, 65, 10)) { + file_size_buf[0] = '0'; + file_size_buf[1] = '\0'; + } +#else + { + int __len = snprintf(file_size_buf, 65, "%lld", total_bytes); + file_size_buf[__len] = '\0'; + } +#endif + size_overflow = 1; + + } else { + ZVAL_LONG(&file_size, total_bytes); + } } if (is_arr_upload) { @@ -1237,7 +1257,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ snprintf(lbuf, llen, "%s_size", param); } if (!is_anonymous) { - safe_php_register_variable_ex(lbuf, &file_size, NULL, 0 TSRMLS_CC); + if (size_overflow) { + ZVAL_STRING(&file_size, file_size_buf, 1); + } + safe_php_register_variable_ex(lbuf, &file_size, NULL, size_overflow TSRMLS_CC); } /* Add $foo[size] */ @@ -1246,7 +1269,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } else { snprintf(lbuf, llen, "%s[size]", param); } - register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, 0 TSRMLS_CC); + if (size_overflow) { + ZVAL_STRING(&file_size, file_size_buf, 1); + } + register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, size_overflow TSRMLS_CC); } efree(param); } diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 9c051a5921..8c3836fea0 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -109,9 +109,9 @@ PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC } /* }}} */ -static void php_glob_stream_path_split(glob_s_t *pglob, char *path, int get_path, char **p_file TSRMLS_DC) /* {{{ */ +static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int get_path, const char **p_file TSRMLS_DC) /* {{{ */ { - char *pos, *gpath = path; + const char *pos, *gpath = path; if ((pos = strrchr(path, '/')) != NULL) { path = pos+1; @@ -141,7 +141,7 @@ static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count T { glob_s_t *pglob = (glob_s_t *)stream->abstract; php_stream_dirent *ent = (php_stream_dirent*)buf; - char *path; + const char *path; /* avoid problems if someone mis-uses the stream */ if (count == sizeof(php_stream_dirent) && pglob) { @@ -206,12 +206,12 @@ php_stream_ops php_glob_stream_ops = { }; /* {{{ php_glob_stream_opener */ -static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *path, char *mode, +static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { glob_s_t *pglob; int ret; - char *tmp, *pos; + const char *tmp, *pos; if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) { return NULL; diff --git a/main/streams/memory.c b/main/streams/memory.c index 328d3be399..90780ea78f 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -598,7 +598,9 @@ PHPAPI php_stream_ops php_stream_rfc2397_ops = { php_stream_temp_set_option }; -static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */ +static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, const char *path, + const char *mode, int options, char **opened_path, + php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */ { php_stream *stream; php_stream_temp_data *ts; @@ -640,11 +642,11 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, cha MAKE_STD_ZVAL(meta); array_init(meta); if (!semi) { /* there is only a mime type */ - add_assoc_stringl(meta, "mediatype", path, mlen, 1); + add_assoc_stringl(meta, "mediatype", (char *) path, mlen, 1); mlen = 0; } else if (sep && sep < semi) { /* there is a mime type */ plen = semi - path; - add_assoc_stringl(meta, "mediatype", path, plen, 1); + add_assoc_stringl(meta, "mediatype", (char *) path, plen, 1); mlen -= plen; path += plen; } else if (semi != path || mlen != sizeof(";base64")-1 || memcmp(path, ";base64", sizeof(";base64")-1)) { /* must be error since parameters are only allowed after mediatype */ diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h index d88b30c479..6700df0b29 100644 --- a/main/streams/php_stream_plain_wrapper.h +++ b/main/streams/php_stream_plain_wrapper.h @@ -30,7 +30,7 @@ BEGIN_EXTERN_C() PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC); #define php_stream_fopen(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened), 0 STREAMS_CC TSRMLS_CC) -PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC); +PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC); #define php_stream_fopen_with_path(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened), 0 STREAMS_CC TSRMLS_CC) PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC); diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h index c2d911032e..15ba09430f 100644 --- a/main/streams/php_stream_transport.h +++ b/main/streams/php_stream_transport.h @@ -26,16 +26,16 @@ # include <sys/socket.h> #endif -typedef php_stream *(php_stream_transport_factory_func)(const char *proto, long protolen, - char *resourcename, long resourcenamelen, +typedef php_stream *(php_stream_transport_factory_func)(const char *proto, size_t protolen, + const char *resourcename, size_t resourcenamelen, const char *persistent_id, int options, int flags, struct timeval *timeout, php_stream_context *context STREAMS_DC TSRMLS_DC); typedef php_stream_transport_factory_func *php_stream_transport_factory; BEGIN_EXTERN_C() -PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC); -PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC); +PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC); +PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC); #define STREAM_XPORT_CLIENT 0 #define STREAM_XPORT_SERVER 1 @@ -46,7 +46,7 @@ PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC); #define STREAM_XPORT_CONNECT_ASYNC 16 /* Open a client or server socket connection */ -PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options, +PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options, int flags, const char *persistent_id, struct timeval *timeout, php_stream_context *context, @@ -59,13 +59,13 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int /* Bind the stream to a local address */ PHPAPI int php_stream_xport_bind(php_stream *stream, - const char *name, long namelen, + const char *name, size_t namelen, char **error_text TSRMLS_DC); /* Connect to a remote address */ PHPAPI int php_stream_xport_connect(php_stream *stream, - const char *name, long namelen, + const char *name, size_t namelen, int asynchronous, struct timeval *timeout, char **error_text, @@ -141,7 +141,7 @@ typedef struct _php_stream_xport_param { struct { char *name; - long namelen; + size_t namelen; int backlog; struct timeval *timeout; struct sockaddr *addr; @@ -170,10 +170,14 @@ typedef enum { STREAM_CRYPTO_METHOD_SSLv3_CLIENT, STREAM_CRYPTO_METHOD_SSLv23_CLIENT, STREAM_CRYPTO_METHOD_TLS_CLIENT, + STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT, + STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, STREAM_CRYPTO_METHOD_SSLv2_SERVER, STREAM_CRYPTO_METHOD_SSLv3_SERVER, STREAM_CRYPTO_METHOD_SSLv23_SERVER, - STREAM_CRYPTO_METHOD_TLS_SERVER + STREAM_CRYPTO_METHOD_TLS_SERVER, + STREAM_CRYPTO_METHOD_TLSv1_1_SERVER, + STREAM_CRYPTO_METHOD_TLSv1_2_SERVER } php_stream_xport_crypt_method_t; BEGIN_EXTERN_C() diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 02f46ab273..c2ead6da4a 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -853,7 +853,7 @@ static php_stream_ops php_plain_files_dirstream_ops = { NULL /* set_option */ }; -static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, char *path, char *mode, +static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { DIR *dir = NULL; @@ -991,7 +991,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha /* }}} */ -static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, char *path, char *mode, +static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) { @@ -1001,7 +1001,7 @@ static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, ch return php_stream_fopen_rel(path, mode, opened_path, options); } -static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) +static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) { char *p; @@ -1031,7 +1031,7 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, in return VCWD_STAT(url, &ssb->sb); } -static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) +static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) { char *p; int ret; @@ -1060,7 +1060,7 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int op return 1; } -static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC) +static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC) { char *p; int ret; @@ -1149,7 +1149,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c return 1; } -static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mode, int options, php_stream_context *context TSRMLS_DC) +static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, int mode, int options, php_stream_context *context TSRMLS_DC) { int ret, recursive = options & PHP_STREAM_MKDIR_RECURSIVE; char *p; @@ -1237,7 +1237,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod } } -static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) +static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) { #if PHP_WIN32 int url_len = strlen(url); @@ -1264,7 +1264,7 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int opt return 1; } -static int php_plain_files_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC) +static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC) { struct utimbuf *newtime; char *p; @@ -1373,10 +1373,11 @@ php_stream_wrapper php_plain_files_wrapper = { }; /* {{{ php_stream_fopen_with_path */ -PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC) +PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC) { /* code ripped off from fopen_wrappers.c */ - char *pathbuf, *ptr, *end; + char *pathbuf, *end; + const char *ptr; const char *exec_fname; char trypath[MAXPATHLEN]; php_stream *stream; @@ -1437,7 +1438,7 @@ not_relative_path: php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s/%s path was truncated to %d", cwd, filename, MAXPATHLEN); } - free(cwd); + efree(cwd); if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) { return NULL; diff --git a/main/streams/streams.c b/main/streams/streams.c index 823b8859bf..d74f9fd04a 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -803,7 +803,7 @@ PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC) return EOF; } -PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC) +PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC) { int len; char newline[2] = "\n"; /* is this OK for Win? */ @@ -835,11 +835,11 @@ PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_D return (stream->ops->stat)(stream, ssb TSRMLS_CC); } -PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC) +PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC) { size_t avail; - char *cr, *lf, *eol = NULL; - char *readptr; + const char *cr, *lf, *eol = NULL; + const char *readptr; if (!buf) { readptr = stream->readbuf + stream->readpos; @@ -911,7 +911,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, if (avail > 0) { size_t cpysz = 0; char *readptr; - char *eol; + const char *eol; int done = 0; readptr = stream->readbuf + stream->readpos; @@ -994,11 +994,11 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, #define STREAM_BUFFERED_AMOUNT(stream) \ ((size_t)(((stream)->writepos) - (stream)->readpos)) -static char *_php_stream_search_delim(php_stream *stream, - size_t maxlen, - size_t skiplen, - char *delim, /* non-empty! */ - size_t delim_len TSRMLS_DC) +static const char *_php_stream_search_delim(php_stream *stream, + size_t maxlen, + size_t skiplen, + const char *delim, /* non-empty! */ + size_t delim_len TSRMLS_DC) { size_t seek_len; @@ -1018,10 +1018,10 @@ static char *_php_stream_search_delim(php_stream *stream, } } -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC) +PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC) { - char *ret_buf, /* returned buffer */ - *found_delim = NULL; + char *ret_buf; /* returned buffer */ + const char *found_delim = NULL; size_t buffered_len, tent_ret_len; /* tentative returned length */ int has_delim = delim_len > 0; @@ -1676,9 +1676,9 @@ int php_shutdown_stream_wrappers(int module_number TSRMLS_DC) /* Validate protocol scheme names during registration * Must conform to /^[a-zA-Z0-9+.-]+$/ */ -static inline int php_stream_wrapper_scheme_validate(char *protocol, int protocol_len) +static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsigned int protocol_len) { - int i; + unsigned int i; for(i = 0; i < protocol_len; i++) { if (!isalnum((int)protocol[i]) && @@ -1693,9 +1693,9 @@ static inline int php_stream_wrapper_scheme_validate(char *protocol, int protoco } /* API for registering GLOBAL wrappers */ -PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) +PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) { - int protocol_len = strlen(protocol); + unsigned int protocol_len = strlen(protocol); if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) { return FAILURE; @@ -1704,7 +1704,7 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); } -PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC) +PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC) { return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1); } @@ -1719,9 +1719,9 @@ static void clone_wrapper_hash(TSRMLS_D) } /* API for registering VOLATILE wrappers */ -PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) +PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) { - int protocol_len = strlen(protocol); + unsigned int protocol_len = strlen(protocol); if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) { return FAILURE; @@ -1734,7 +1734,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); } -PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC) +PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC) { if (!FG(stream_wrappers)) { clone_wrapper_hash(TSRMLS_C); @@ -1745,7 +1745,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC) /* }}} */ /* {{{ php_stream_locate_url_wrapper */ -PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC) +PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC) { HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash); php_stream_wrapper **wrapperpp = NULL; @@ -1880,7 +1880,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char /* {{{ _php_stream_mkdir */ -PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC) +PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context TSRMLS_DC) { php_stream_wrapper *wrapper = NULL; @@ -1895,7 +1895,7 @@ PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_conte /* {{{ _php_stream_rmdir */ -PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC) +PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context TSRMLS_DC) { php_stream_wrapper *wrapper = NULL; @@ -1909,10 +1909,10 @@ PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *contex /* }}} */ /* {{{ _php_stream_stat_path */ -PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) +PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) { php_stream_wrapper *wrapper = NULL; - char *path_to_open = path; + const char *path_to_open = path; int ret; /* Try to hit the cache first */ @@ -1954,12 +1954,12 @@ PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, /* }}} */ /* {{{ php_stream_opendir */ -PHPAPI php_stream *_php_stream_opendir(char *path, int options, +PHPAPI php_stream *_php_stream_opendir(const char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC) { php_stream *stream = NULL; php_stream_wrapper *wrapper = NULL; - char *path_to_open; + const char *path_to_open; if (!path || !*path) { return NULL; @@ -2003,12 +2003,12 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_ /* }}} */ /* {{{ php_stream_open_wrapper_ex */ -PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, +PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { php_stream *stream = NULL; php_stream_wrapper *wrapper = NULL; - char *path_to_open; + const char *path_to_open; int persistent = options & STREAM_OPEN_PERSISTENT; char *resolved_path = NULL; char *copy_of_path = NULL; @@ -2264,7 +2264,7 @@ PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b) /* {{{ php_stream_scandir */ -PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context, +PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags, php_stream_context *context, int (*compare) (const char **a, const char **b) TSRMLS_DC) { php_stream *stream; diff --git a/main/streams/transports.c b/main/streams/transports.c index c24bf97ce6..2d31074ded 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -29,12 +29,12 @@ PHPAPI HashTable *php_stream_xport_get_hash(void) return &xport_hash; } -PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC) +PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC) { return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL); } -PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC) +PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC) { return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1); } @@ -49,7 +49,7 @@ PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC) if (local_err) { efree(local_err); local_err = NULL; } \ } -PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options, +PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options, int flags, const char *persistent_id, struct timeval *timeout, php_stream_context *context, @@ -194,7 +194,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int /* Bind the stream to a local address */ PHPAPI int php_stream_xport_bind(php_stream *stream, - const char *name, long namelen, + const char *name, size_t namelen, char **error_text TSRMLS_DC) { @@ -222,7 +222,7 @@ PHPAPI int php_stream_xport_bind(php_stream *stream, /* Connect to a remote address */ PHPAPI int php_stream_xport_connect(php_stream *stream, - const char *name, long namelen, + const char *name, size_t namelen, int asynchronous, struct timeval *timeout, char **error_text, diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 69edbaafa9..1e626e4b4c 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -45,14 +45,14 @@ struct php_user_stream_wrapper { php_stream_wrapper wrapper; }; -static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); -static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); -static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC); -static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode, +static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); +static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); +static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC); +static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC); +static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC); +static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC); +static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC); +static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); static php_stream_wrapper_ops user_stream_wops = { @@ -332,7 +332,8 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph return object; } -static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) +static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, + int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; php_userstream_data_t *us; @@ -437,7 +438,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena return stream; } -static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode, +static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; @@ -1151,7 +1152,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value } -static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) +static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; zval *zfilename, *zfuncname, *zretval; @@ -1198,7 +1199,8 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio return ret; } -static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC) +static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, + int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; zval *zold_name, *znew_name, *zfuncname, *zretval; @@ -1250,7 +1252,8 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char return ret; } -static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC) +static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, + int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval; @@ -1308,7 +1311,8 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, return ret; } -static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) +static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, + int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; zval *zfilename, *zoptions, *zfuncname, *zretval; @@ -1361,7 +1365,8 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int option return ret; } -static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC) +static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, + void *value, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; zval *zfilename, *zoption, *zvalue, *zfuncname, *zretval; @@ -1444,7 +1449,8 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int opt } -static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) +static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, + php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; zval *zfilename, *zfuncname, *zretval, *zflags; diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 34a106e280..0366027c1d 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -230,7 +230,7 @@ static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC #endif } -static inline int sock_sendto(php_netstream_data_t *sock, char *buf, size_t buflen, int flags, +static inline int sock_sendto(php_netstream_data_t *sock, const char *buf, size_t buflen, int flags, struct sockaddr *addr, socklen_t addrlen TSRMLS_DC) { @@ -521,7 +521,7 @@ static inline int parse_unix_address(php_stream_xport_param *xparam, struct sock } #endif -static inline char *parse_ip_address_ex(const char *str, int str_len, int *portno, int get_err, char **err TSRMLS_DC) +static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *portno, int get_err, char **err TSRMLS_DC) { char *colon; char *host = NULL; @@ -774,8 +774,8 @@ static int php_tcp_sockop_set_option(php_stream *stream, int option, int value, } -PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, long protolen, - char *resourcename, long resourcenamelen, +PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t protolen, + const char *resourcename, size_t resourcenamelen, const char *persistent_id, int options, int flags, struct timeval *timeout, php_stream_context *context STREAMS_DC TSRMLS_DC) |