diff options
Diffstat (limited to 'main')
68 files changed, 1825 insertions, 1901 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index f9e9ccb049..b1be4443d2 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -57,10 +57,15 @@ SAPI_API int sapi_globals_id; sapi_globals_struct sapi_globals; #endif +static void _type_dtor(zval *zv) +{ + free(Z_PTR_P(zv)); +} + static void sapi_globals_ctor(sapi_globals_struct *sapi_globals TSRMLS_DC) { memset(sapi_globals, 0, sizeof(*sapi_globals)); - zend_hash_init_ex(&sapi_globals->known_post_content_types, 5, NULL, NULL, 1, 0); + zend_hash_init_ex(&sapi_globals->known_post_content_types, 8, NULL, _type_dtor, 1, 0); php_setup_sapi_content_types(TSRMLS_C); } @@ -124,26 +129,21 @@ SAPI_API void sapi_free_header(sapi_header_struct *sapi_header) PHP_FUNCTION(header_register_callback) { zval *callback_func; - char *callback_name; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callback_func) == FAILURE) { return; } - if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) { - efree(callback_name); + if (!zend_is_callable(callback_func, 0, NULL TSRMLS_CC)) { RETURN_FALSE; } - efree(callback_name); - - if (SG(callback_func)) { + if (Z_TYPE(SG(callback_func)) != IS_UNDEF) { zval_ptr_dtor(&SG(callback_func)); SG(fci_cache) = empty_fcall_info_cache; } - SG(callback_func) = callback_func; - - Z_ADDREF_P(SG(callback_func)); + ZVAL_COPY(&SG(callback_func), callback_func); RETURN_TRUE; } @@ -153,27 +153,23 @@ static void sapi_run_header_callback(TSRMLS_D) { int error; zend_fcall_info fci; - char *callback_name = NULL; char *callback_error = NULL; - zval *retval_ptr = NULL; + zval retval; - if (zend_fcall_info_init(SG(callback_func), 0, &fci, &SG(fci_cache), &callback_name, &callback_error TSRMLS_CC) == SUCCESS) { - fci.retval_ptr_ptr = &retval_ptr; + if (zend_fcall_info_init(&SG(callback_func), 0, &fci, &SG(fci_cache), NULL, &callback_error TSRMLS_CC) == SUCCESS) { + fci.retval = &retval; error = zend_call_function(&fci, &SG(fci_cache) TSRMLS_CC); if (error == FAILURE) { goto callback_failed; - } else if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); + } else { + zval_ptr_dtor(&retval); } } else { callback_failed: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the sapi_header_callback"); } - if (callback_name) { - efree(callback_name); - } if (callback_error) { efree(callback_error); } @@ -191,7 +187,7 @@ SAPI_API void sapi_handle_post(void *arg TSRMLS_DC) static void sapi_read_post_data(TSRMLS_D) { sapi_post_entry *post_entry; - uint content_type_length = strlen(SG(request_info).content_type); + uint content_type_length = (uint)strlen(SG(request_info).content_type); char *content_type = estrndup(SG(request_info).content_type, content_type_length); char *p; char oldchar=0; @@ -218,8 +214,8 @@ static void sapi_read_post_data(TSRMLS_D) } /* now try to find an appropriate POST content handler */ - if (zend_hash_find(&SG(known_post_content_types), content_type, - content_type_length+1, (void **) &post_entry) == SUCCESS) { + if ((post_entry = zend_hash_str_find_ptr(&SG(known_post_content_types), content_type, + content_type_length)) != NULL) { /* found one, register it for use */ SG(request_info).post_entry = post_entry; post_reader_func = post_entry->post_reader; @@ -256,7 +252,7 @@ SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC) return -1; } - read_bytes = sapi_module.read_post(buffer, buflen TSRMLS_CC); + read_bytes = (int)sapi_module.read_post(buffer, buflen TSRMLS_CC); if (read_bytes > 0) { /* gogo */ @@ -273,7 +269,7 @@ SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC) 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", + php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %pd bytes exceeds the limit of %pd bytes", SG(request_info).content_length, SG(post_max_size)); return; } @@ -294,7 +290,7 @@ SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) } 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)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds " ZEND_LONG_FMT " bytes", SG(post_max_size)); break; } @@ -315,14 +311,14 @@ static inline char *get_default_content_type(uint prefix_len, uint *len TSRMLS_D if (SG(default_mimetype)) { mimetype = SG(default_mimetype); - mimetype_len = strlen(SG(default_mimetype)); + mimetype_len = (uint)strlen(SG(default_mimetype)); } else { mimetype = SAPI_DEFAULT_MIMETYPE; mimetype_len = sizeof(SAPI_DEFAULT_MIMETYPE) - 1; } if (SG(default_charset)) { charset = SG(default_charset); - charset_len = strlen(SG(default_charset)); + charset_len = (uint)strlen(SG(default_charset)); } else { charset = SAPI_DEFAULT_CHARSET; charset_len = sizeof(SAPI_DEFAULT_CHARSET) - 1; @@ -453,7 +449,7 @@ SAPI_API void sapi_activate(TSRMLS_D) SG(sapi_headers).mimetype = NULL; SG(headers_sent) = 0; SG(callback_run) = 0; - SG(callback_func) = NULL; + ZVAL_UNDEF(&SG(callback_func)); SG(read_post_bytes) = 0; SG(request_info).request_body = NULL; SG(request_info).current_user = NULL; @@ -550,9 +546,7 @@ SAPI_API void sapi_deactivate(TSRMLS_D) SG(sapi_started) = 0; SG(headers_sent) = 0; SG(callback_run) = 0; - if (SG(callback_func)) { - zval_ptr_dtor(&SG(callback_func)); - } + zval_ptr_dtor(&SG(callback_func)); SG(request_info).headers_read = 0; SG(global_request_time) = 0; } @@ -658,7 +652,7 @@ static void sapi_header_add_op(sapi_header_op_enum op, sapi_header_struct *sapi_ char sav = *colon_offset; *colon_offset = 0; - sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, strlen(sapi_header->header)); + sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, (int)strlen(sapi_header->header)); *colon_offset = sav; } } @@ -745,7 +739,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) return SUCCESS; } else { /* new line/NUL character safety check */ - int i; + uint i; for (i = 0; i < header_line_len; i++) { /* RFC 2616 allows new lines if followed by SP or HT */ int illegal_break = @@ -795,7 +789,9 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) /* Disable possible output compression for images */ if (!strncmp(ptr, "image/", sizeof("image/")-1)) { - zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0); + zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(key); } mimetype = estrdup(ptr); @@ -810,7 +806,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) PHP_STRLCPY(newheader, "Content-type: ", newlen, sizeof("Content-type: ")-1); strlcat(newheader, mimetype, newlen); sapi_header.header = newheader; - sapi_header.header_len = newlen - 1; + sapi_header.header_len = (uint)(newlen - 1); efree(header_line); } efree(mimetype); @@ -821,8 +817,10 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) * do disable compression altogether. This contributes to making scripts * portable between setups that have and don't have zlib compression * enabled globally. See req #44164 */ - zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), + zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0); + zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + zend_string_release(key); } else if (!STRCASECMP(header_line, "Location")) { if ((SG(sapi_headers).http_response_code < 300 || SG(sapi_headers).http_response_code > 399) && @@ -880,7 +878,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D) SG(sapi_headers).send_default_content_type = 0; } - if (SG(callback_func) && !SG(callback_run)) { + if (Z_TYPE(SG(callback_func)) != IS_UNDEF && !SG(callback_run)) { SG(callback_run) = 1; sapi_run_header_callback(TSRMLS_C); } @@ -903,7 +901,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D) if (SG(sapi_headers).http_status_line) { http_status_line.header = SG(sapi_headers).http_status_line; - http_status_line.header_len = strlen(SG(sapi_headers).http_status_line); + http_status_line.header_len = (uint)strlen(SG(sapi_headers).http_status_line); } else { http_status_line.header = buf; http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code); @@ -949,27 +947,27 @@ SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries TSRMLS_DC) SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC) { - if (SG(sapi_started) && EG(in_execution)) { + if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } - return zend_hash_add(&SG(known_post_content_types), - post_entry->content_type, post_entry->content_type_len+1, - (void *) post_entry, sizeof(sapi_post_entry), NULL); + return zend_hash_str_add_mem(&SG(known_post_content_types), + post_entry->content_type, post_entry->content_type_len, + (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE; } SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC) { - if (SG(sapi_started) && EG(in_execution)) { + if (SG(sapi_started) && EG(current_execute_data)) { return; } - zend_hash_del(&SG(known_post_content_types), post_entry->content_type, - post_entry->content_type_len+1); + zend_hash_str_del(&SG(known_post_content_types), post_entry->content_type, + post_entry->content_type_len); } SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D) TSRMLS_DC) { - if (SG(sapi_started) && EG(in_execution)) { + if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } sapi_module.default_post_reader = default_post_reader; @@ -979,16 +977,16 @@ SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRML SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC) TSRMLS_DC) { - if (SG(sapi_started) && EG(in_execution)) { + if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } sapi_module.treat_data = treat_data; return SUCCESS; } -SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D) TSRMLS_DC) +SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D) TSRMLS_DC) { - if (SG(sapi_started) && EG(in_execution)) { + if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } sapi_module.input_filter = input_filter; @@ -999,14 +997,14 @@ SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, ch SAPI_API int sapi_flush(TSRMLS_D) { if (sapi_module.flush) { - sapi_module.flush(SG(server_context)); + sapi_module.flush(SG(server_context) TSRMLS_CC); return SUCCESS; } else { return FAILURE; } } -SAPI_API struct stat *sapi_get_stat(TSRMLS_D) +SAPI_API zend_stat_t *sapi_get_stat(TSRMLS_D) { if (sapi_module.get_stat) { return sapi_module.get_stat(TSRMLS_C); diff --git a/main/SAPI.h b/main/SAPI.h index 990ca6990c..79661371d9 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -31,6 +31,7 @@ #include "win32/php_stdint.h" #endif #include <sys/stat.h> +#include "php.h" #define SAPI_OPTION_NO_CHDIR 1 #define SAPI_POST_BLOCK_SIZE 0x4000 @@ -81,7 +82,7 @@ typedef struct { const char *request_method; char *query_string; char *cookie_data; - long content_length; + zend_long content_length; char *path_translated; char *request_uri; @@ -124,16 +125,16 @@ typedef struct _sapi_globals_struct { int64_t read_post_bytes; unsigned char post_read; unsigned char headers_sent; - struct stat global_stat; + zend_stat_t global_stat; char *default_mimetype; char *default_charset; HashTable *rfc1867_uploaded_files; - long post_max_size; + zend_long post_max_size; int options; zend_bool sapi_started; double global_request_time; HashTable known_post_content_types; - zval *callback_func; + zval callback_func; zend_fcall_info_cache fci_cache; zend_bool callback_run; } sapi_globals_struct; @@ -169,7 +170,7 @@ END_EXTERN_C() typedef struct { char *line; /* If you allocated this, you need to free it yourself */ uint line_len; - long response_code; /* long due to zend_parse_parameters compatibility */ + zend_long response_code; /* long due to zend_parse_parameters compatibility */ } sapi_header_line; typedef enum { /* Parameter: */ @@ -197,10 +198,10 @@ 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); SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D) TSRMLS_DC); SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC) TSRMLS_DC); -SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D) TSRMLS_DC); +SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D) TSRMLS_DC); SAPI_API int sapi_flush(TSRMLS_D); -SAPI_API struct stat *sapi_get_stat(TSRMLS_D); +SAPI_API zend_stat_t *sapi_get_stat(TSRMLS_D); SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC); SAPI_API char *sapi_get_default_content_type(TSRMLS_D); @@ -227,9 +228,9 @@ struct _sapi_module_struct { int (*activate)(TSRMLS_D); int (*deactivate)(TSRMLS_D); - int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC); - void (*flush)(void *server_context); - struct stat *(*get_stat)(TSRMLS_D); + size_t (*ub_write)(const char *str, size_t str_length TSRMLS_DC); + void (*flush)(void *server_context TSRMLS_DC); + zend_stat_t *(*get_stat)(TSRMLS_D); char *(*getenv)(char *name, size_t name_len TSRMLS_DC); void (*sapi_error)(int type, const char *error_msg, ...); @@ -238,7 +239,7 @@ struct _sapi_module_struct { int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC); void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC); - int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC); + size_t (*read_post)(char *buffer, size_t count_bytes TSRMLS_DC); char *(*read_cookies)(TSRMLS_D); void (*register_server_variables)(zval *track_vars_array TSRMLS_DC); @@ -265,7 +266,7 @@ struct _sapi_module_struct { int (*get_target_uid)(uid_t * TSRMLS_DC); int (*get_target_gid)(gid_t * TSRMLS_DC); - unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC); + unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len TSRMLS_DC); void (*ini_defaults)(HashTable *configuration_hash); int phpinfo_as_text; @@ -299,7 +300,7 @@ struct _sapi_post_entry { #define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg TSRMLS_DC) #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray TSRMLS_DC) -#define SAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC) +#define SAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, char *var, char **val, size_t val_len, size_t *new_val_len TSRMLS_DC) BEGIN_EXTERN_C() SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); diff --git a/main/build-defs.h.in b/main/build-defs.h.in index aa1fbf0321..6821b631f5 100644 --- a/main/build-defs.h.in +++ b/main/build-defs.h.in @@ -1,6 +1,6 @@ /* -*- C -*- +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 3be7b5f206..b5b12eba56 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -94,24 +94,24 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir) if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN || stage == PHP_INI_STAGE_ACTIVATE || stage == PHP_INI_STAGE_DEACTIVATE) { /* We're in a PHP_INI_SYSTEM context, no restrictions */ - *p = new_value; + *p = new_value ? new_value->val : NULL; return SUCCESS; } /* Otherwise we're in runtime */ if (!*p || !**p) { /* open_basedir not set yet, go ahead and give it a value */ - *p = new_value; + *p = new_value->val; return SUCCESS; } /* Shortcut: When we have a open_basedir and someone tries to unset, we know it'll fail */ - if (!new_value || !*new_value) { + if (!new_value || !*new_value->val) { return FAILURE; } /* Is the proposed open_basedir at least as restrictive as the current setting? */ - ptr = pathbuf = estrdup(new_value); + ptr = pathbuf = estrdup(new_value->val); while (ptr && *ptr) { end = strchr(ptr, DEFAULT_DIR_SEPARATOR); if (end != NULL) { @@ -128,7 +128,7 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir) efree(pathbuf); /* Everything checks out, set it */ - *p = new_value; + *p = new_value->val; return SUCCESS; } @@ -157,7 +157,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path strlcpy(local_open_basedir, basedir, sizeof(local_open_basedir)); } - path_len = strlen(path); + path_len = (int)strlen(path); if (path_len > (MAXPATHLEN - 1)) { /* empty and too long paths are invalid */ return -1; @@ -168,7 +168,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path return -1; } - path_len = strlen(resolved_name); + path_len = (int)strlen(resolved_name); memcpy(path_tmp, resolved_name, path_len + 1); /* safe */ while (VCWD_REALPATH(path_tmp, resolved_name) == NULL) { @@ -226,12 +226,13 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path /* Resolve open_basedir to resolved_basedir */ if (expand_filepath(local_open_basedir, resolved_basedir TSRMLS_CC) != NULL) { + int basedir_len = (int)strlen(basedir); /* Handler for basedirs that end with a / */ - resolved_basedir_len = strlen(resolved_basedir); + resolved_basedir_len = (int)strlen(resolved_basedir); #if defined(PHP_WIN32) || defined(NETWARE) - if (basedir[strlen(basedir) - 1] == PHP_DIR_SEPARATOR || basedir[strlen(basedir) - 1] == '/') { + if (basedir[basedir_len - 1] == PHP_DIR_SEPARATOR || basedir[basedir_len - 1] == '/') { #else - if (basedir[strlen(basedir) - 1] == PHP_DIR_SEPARATOR) { + if (basedir[basedir_len - 1] == PHP_DIR_SEPARATOR) { #endif if (resolved_basedir[resolved_basedir_len - 1] != PHP_DIR_SEPARATOR) { resolved_basedir[resolved_basedir_len] = PHP_DIR_SEPARATOR; @@ -242,7 +243,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path resolved_basedir[resolved_basedir_len] = '\0'; } - resolved_name_len = strlen(resolved_name); + resolved_name_len = (int)strlen(resolved_name); if (path_tmp[path_len - 1] == PHP_DIR_SEPARATOR) { if (resolved_name[resolved_name_len - 1] != PHP_DIR_SEPARATOR) { resolved_name[resolved_name_len] = PHP_DIR_SEPARATOR; @@ -408,9 +409,9 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC) } } else #endif - if (PG(doc_root) && path_info && (length = strlen(PG(doc_root))) && + if (PG(doc_root) && path_info && (length = (int)strlen(PG(doc_root))) && IS_ABSOLUTE_PATH(PG(doc_root), length)) { - int path_len = strlen(path_info); + int path_len = (int)strlen(path_info); filename = emalloc(length + path_len + 2); if (filename) { memcpy(filename, PG(doc_root), length); @@ -428,19 +429,23 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC) if (filename) { - resolved_path = zend_resolve_path(filename, strlen(filename) TSRMLS_CC); + resolved_path = zend_resolve_path(filename, (int)strlen(filename) TSRMLS_CC); } if (!resolved_path) { if (SG(request_info).path_translated != filename) { - STR_FREE(filename); + if (filename) { + efree(filename); + } } /* we have to free SG(request_info).path_translated here because * php_destroy_request_info assumes that it will get * freed when the include_names hash is emptied, but * we're not adding it in this case */ - STR_FREE(SG(request_info).path_translated); - SG(request_info).path_translated = NULL; + if (SG(request_info).path_translated) { + efree(SG(request_info).path_translated); + SG(request_info).path_translated = NULL; + } return FAILURE; } efree(resolved_path); @@ -450,16 +455,22 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC) if (zend_stream_open(filename, file_handle TSRMLS_CC) == FAILURE) { PG(display_errors) = orig_display_errors; if (SG(request_info).path_translated != filename) { - STR_FREE(filename); + if (filename) { + efree(filename); + } + } + if (SG(request_info).path_translated) { + efree(SG(request_info).path_translated); + SG(request_info).path_translated = NULL; } - STR_FREE(SG(request_info).path_translated); /* for same reason as above */ - SG(request_info).path_translated = NULL; return FAILURE; } PG(display_errors) = orig_display_errors; if (SG(request_info).path_translated != filename) { - STR_FREE(SG(request_info).path_translated); /* for same reason as above */ + if (SG(request_info).path_translated) { + efree(SG(request_info).path_translated); + } SG(request_info).path_translated = filename; } @@ -531,7 +542,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c memcpy(trypath+(end-ptr)+1, filename, filename_length+1); ptr = end+1; } else { - int len = strlen(ptr); + int len = (int)strlen(ptr); if (len + 1 + filename_length + 1 >= MAXPATHLEN) { break; @@ -566,7 +577,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c */ if (zend_is_executing(TSRMLS_C)) { const char *exec_fname = zend_get_executed_filename(TSRMLS_C); - int exec_fname_length = strlen(exec_fname); + int exec_fname_length = (int)strlen(exec_fname); while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); if (exec_fname && exec_fname[0] != '[' && @@ -626,7 +637,7 @@ PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const c return NULL; } - filename_length = strlen(filename); + filename_length = (int)strlen(filename); /* Relative path open */ if ((*filename == '.') @@ -643,8 +654,8 @@ PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const c */ if (zend_is_executing(TSRMLS_C)) { exec_fname = zend_get_executed_filename(TSRMLS_C); - exec_fname_length = strlen(exec_fname); - path_length = strlen(path); + exec_fname_length = (int)strlen(exec_fname); + path_length = (int)strlen(path); while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); if ((exec_fname && exec_fname[0] == '[') || exec_fname_length <= 0) { @@ -748,10 +759,15 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co cwd_state new_state; char cwd[MAXPATHLEN]; int copy_len; + int path_len; if (!filepath[0]) { return NULL; - } else if (IS_ABSOLUTE_PATH(filepath, strlen(filepath))) { + } + + path_len = (int)strlen(filepath); + + if (IS_ABSOLUTE_PATH(filepath, path_len)) { cwd[0] = '\0'; } else { const char *iam = SG(request_info).path_translated; @@ -774,7 +790,7 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co /* return a relative file path if for any reason * we cannot cannot getcwd() and the requested, * relatively referenced file is accessible */ - copy_len = strlen(filepath) > MAXPATHLEN - 1 ? MAXPATHLEN - 1 : strlen(filepath); + copy_len = path_len > MAXPATHLEN - 1 ? MAXPATHLEN - 1 : path_len; if (real_path) { memcpy(real_path, filepath, copy_len); real_path[copy_len] = '\0'; @@ -792,7 +808,7 @@ PHPAPI char *expand_filepath_with_mode(const char *filepath, char *real_path, co } new_state.cwd = estrdup(cwd); - new_state.cwd_length = strlen(cwd); + new_state.cwd_length = (int)strlen(cwd); if (virtual_file_ex(&new_state, filepath, NULL, realpath_mode TSRMLS_CC)) { efree(new_state.cwd); diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h index 4dde0e35eb..b58f54dce8 100644 --- a/main/fopen_wrappers.h +++ b/main/fopen_wrappers.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/getopt.c b/main/getopt.c index 258173fc22..9338648b10 100644 --- a/main/getopt.c +++ b/main/getopt.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -88,8 +88,8 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char } } if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { - char *pos; - int arg_end = strlen(argv[*optind])-1; + const char *pos; + int arg_end = (int)strlen(argv[*optind])-1; /* '--' indicates end of args if not followed by a known long option name */ if (argv[*optind][2] == '\0') { @@ -119,7 +119,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char optchr = 0; dash = 0; - arg_start += strlen(opts[php_optidx].opt_name); + arg_start += (int)strlen(opts[php_optidx].opt_name); } else { if (!dash) { dash = 1; diff --git a/main/internal_functions.c.in b/main/internal_functions.c.in index f1e66b160a..3f02921ddf 100644 --- a/main/internal_functions.c.in +++ b/main/internal_functions.c.in @@ -1,6 +1,6 @@ /* -*- C -*- +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/internal_functions_nw.c b/main/internal_functions_nw.c index 86ba57d486..dcb84c346c 100644 --- a/main/internal_functions_nw.c +++ b/main/internal_functions_nw.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/internal_functions_win32.c b/main/internal_functions_win32.c index 8b5518ca90..b4718c379f 100644 --- a/main/internal_functions_win32.c +++ b/main/internal_functions_win32.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -29,10 +29,6 @@ #include <stdlib.h> #include <stdio.h> -#ifndef ZEND_ENGINE_2 -#error HEAD does not work with ZendEngine1 anymore -#endif - #include "ext/standard/dl.h" #include "ext/standard/file.h" #include "ext/standard/fsock.h" diff --git a/main/main.c b/main/main.c index 45d33434cf..b58a643e84 100644 --- a/main/main.c +++ b/main/main.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -53,6 +53,7 @@ #include <locale.h> #endif #include "zend.h" +#include "zend_types.h" #include "zend_extensions.h" #include "php_ini.h" #include "php_globals.h" @@ -129,13 +130,13 @@ PHPAPI int core_globals_id; #ifdef PHP_WIN32 #include "win32_internal_function_disabled.h" -static php_win32_disable_functions(TSRMLS_D) +static int php_win32_disable_functions(TSRMLS_D) { int i; if (EG(windows_version_info).dwMajorVersion < 5) { for (i = 0; i < function_name_cnt_5; i++) { - if (zend_hash_del(CG(function_table), function_name_5[i], strlen(function_name_5[i]) + 1)==FAILURE) { + if (zend_hash_str_del(CG(function_table), function_name_5[i], strlen(function_name_5[i]))==FAILURE) { php_printf("Unable to disable function '%s'\n", function_name_5[i]); return FAILURE; } @@ -144,7 +145,7 @@ static php_win32_disable_functions(TSRMLS_D) if (EG(windows_version_info).dwMajorVersion < 6) { for (i = 0; i < function_name_cnt_6; i++) { - if (zend_hash_del(CG(function_table), function_name_6[i], strlen(function_name_6[i]) + 1)==FAILURE) { + if (zend_hash_str_del(CG(function_table), function_name_6[i], strlen(function_name_6[i]))==FAILURE) { php_printf("Unable to disable function '%s'\n", function_name_6[i]); return FAILURE; } @@ -160,7 +161,9 @@ static php_win32_disable_functions(TSRMLS_D) */ static PHP_INI_MH(OnSetPrecision) { - int i = atoi(new_value); + zend_long i; + + ZEND_ATOL(i, new_value->val); if (i >= 0) { EG(precision) = i; return SUCCESS; @@ -175,11 +178,11 @@ static PHP_INI_MH(OnSetPrecision) static PHP_INI_MH(OnChangeMemoryLimit) { if (new_value) { - PG(memory_limit) = zend_atol(new_value, new_value_length); + PG(memory_limit) = zend_atol(new_value->val, (int)new_value->len); } else { PG(memory_limit) = 1<<30; /* effectively, no limit */ } - return zend_set_memory_limit(PG(memory_limit)); + return zend_set_memory_limit(PG(memory_limit) TSRMLS_CC); } /* }}} */ @@ -279,7 +282,7 @@ static void php_binary_init(TSRMLS_D) if ((envpath = getenv("PATH")) != NULL) { char *search_dir, search_path[MAXPATHLEN]; char *last = NULL; - struct stat s; + zend_stat_t s; path = estrdup(envpath); search_dir = php_strtok_r(path, ":", &last); @@ -316,11 +319,11 @@ static PHP_INI_MH(OnUpdateTimeout) { if (stage==PHP_INI_STAGE_STARTUP) { /* Don't set a timeout on startup, only per-request */ - EG(timeout_seconds) = atoi(new_value); + ZEND_ATOL(EG(timeout_seconds), new_value->val); return SUCCESS; } zend_unset_timeout(TSRMLS_C); - EG(timeout_seconds) = atoi(new_value); + ZEND_ATOL(EG(timeout_seconds), new_value->val); zend_set_timeout(EG(timeout_seconds), 0); return SUCCESS; } @@ -347,7 +350,7 @@ static int php_get_display_errors_mode(char *value, int value_length) } else if (value_length == 6 && !strcasecmp(value, "stdout")) { mode = PHP_DISPLAY_ERRORS_STDOUT; } else { - mode = atoi(value); + ZEND_ATOL(mode, value); if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { mode = PHP_DISPLAY_ERRORS_STDOUT; } @@ -361,7 +364,7 @@ static int php_get_display_errors_mode(char *value, int value_length) */ static PHP_INI_MH(OnUpdateDisplayErrors) { - PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length); + PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value->val, (int)new_value->len); return SUCCESS; } @@ -376,11 +379,11 @@ static PHP_INI_DISP(display_errors_mode) TSRMLS_FETCH(); if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL ); - tmp_value_length = ini_entry->orig_value_length; + tmp_value = (ini_entry->orig_value ? ini_entry->orig_value->val : NULL ); + tmp_value_length = (int)ini_entry->orig_value->len; } else if (ini_entry->value) { - tmp_value = ini_entry->value; - tmp_value_length = ini_entry->value_length; + tmp_value = ini_entry->value->val; + tmp_value_length = (int)ini_entry->value->len; } else { tmp_value = NULL; tmp_value_length = 0; @@ -420,9 +423,9 @@ static PHP_INI_DISP(display_errors_mode) static PHP_INI_MH(OnUpdateInternalEncoding) { if (new_value) { - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } else { - OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + PG(internal_encoding) = SG(default_charset); } return SUCCESS; } @@ -433,9 +436,9 @@ static PHP_INI_MH(OnUpdateInternalEncoding) static PHP_INI_MH(OnUpdateInputEncoding) { if (new_value) { - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } else { - OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + PG(input_encoding) = SG(default_charset); } return SUCCESS; } @@ -446,9 +449,9 @@ static PHP_INI_MH(OnUpdateInputEncoding) static PHP_INI_MH(OnUpdateOutputEncoding) { if (new_value) { - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } else { - OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + PG(output_encoding) = SG(default_charset); } return SUCCESS; } @@ -459,12 +462,12 @@ static PHP_INI_MH(OnUpdateOutputEncoding) static PHP_INI_MH(OnUpdateErrorLog) { /* Only do the safemode/open_basedir check at runtime */ - if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value, "syslog")) { - if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) { + if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value->val, "syslog")) { + if (PG(open_basedir) && php_check_open_basedir(new_value->val TSRMLS_CC)) { return FAILURE; } } - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } /* }}} */ @@ -475,11 +478,11 @@ static PHP_INI_MH(OnUpdateMailLog) { /* Only do the safemode/open_basedir check at runtime */ if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) { - if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) { + if (PG(open_basedir) && php_check_open_basedir(new_value->val TSRMLS_CC)) { return FAILURE; } } - OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); return SUCCESS; } /* }}} */ @@ -499,40 +502,6 @@ static PHP_INI_MH(OnChangeMailForceExtra) /* defined in browscap.c */ PHP_INI_MH(OnChangeBrowscap); -/* {{{ PHP_INI_MH - */ -static PHP_INI_MH(OnChangeAlwaysPopulateRawPostData) -{ - signed char *p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (signed char *) (base+(size_t) mh_arg1); - - *p = zend_atol(new_value, new_value_length); - if (new_value_length == 2 && strcasecmp("on", new_value) == 0) { - *p = (signed char) 1; - } - else if (new_value_length == 3 && strcasecmp("yes", new_value) == 0) { - *p = (signed char) 1; - } - else if (new_value_length == 4 && strcasecmp("true", new_value) == 0) { - *p = (signed char) 1; - } - else if (new_value_length == 5 && strcasecmp("never", new_value) == 0) { - *p = (signed char) -1; - } - else { - *p = (signed char) atoi(new_value); - } - return SUCCESS; -} -/* }}} */ /* Need to be read from the environment (?): * PHP_AUTO_PREPEND_FILE @@ -560,7 +529,6 @@ PHP_INI_BEGIN() PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb) - STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals) STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode) STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals) @@ -638,7 +606,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_ENTRY("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeAlwaysPopulateRawPostData, 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) @@ -705,8 +672,8 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC) fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644); if (fd != -1) { char *tmp; - int len; - char *error_time_str; + size_t len; + zend_string *error_time_str; time(&error_time); #ifdef ZTS @@ -718,13 +685,16 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC) #else error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1 TSRMLS_CC); #endif - len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL); + len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str->val, log_message, PHP_EOL); #ifdef PHP_WIN32 php_flock(fd, 2); -#endif + /* XXX should eventually write in a loop if len > UINT_MAX */ + php_ignore_value(write(fd, tmp, (unsigned)len)); +#else php_ignore_value(write(fd, tmp, len)); +#endif efree(tmp); - efree(error_time_str); + zend_string_free(error_time_str); close(fd); PG(in_error_log) = 0; return; @@ -742,7 +712,7 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC) /* {{{ php_write wrapper for modules to use PHPWRITE */ -PHPAPI int php_write(void *buf, uint size TSRMLS_DC) +PHPAPI size_t php_write(void *buf, size_t size TSRMLS_DC) { return PHPWRITE(buf, size); } @@ -750,12 +720,12 @@ PHPAPI int php_write(void *buf, uint size TSRMLS_DC) /* {{{ php_printf */ -PHPAPI int php_printf(const char *format, ...) +PHPAPI size_t php_printf(const char *format, ...) { va_list args; - int ret; + size_t ret; char *buffer; - int size; + size_t size; TSRMLS_FETCH(); va_start(args, format); @@ -776,6 +746,7 @@ PHPAPI int php_printf(const char *format, ...) */ PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) { + zend_string *replace_buffer = NULL, *replace_origin = NULL; char *buffer = NULL, *docref_buf = NULL, *target = NULL; char *docref_target = "", *docref_root = ""; char *p; @@ -789,14 +760,13 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c int is_function = 0; /* get error text into buffer and escape for html if necessary */ - buffer_len = vspprintf(&buffer, 0, format, args); + buffer_len = (int)vspprintf(&buffer, 0, format, args); if (PG(html_errors)) { - size_t len; - char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC); + replace_buffer = php_escape_html_entities(buffer, buffer_len, 0, ENT_COMPAT, NULL TSRMLS_CC); efree(buffer); - buffer = replace; - buffer_len = len; + buffer = replace_buffer->val; + buffer_len = (int)replace_buffer->len; } /* which function caused the problem if any at all */ @@ -805,6 +775,8 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c } else if (php_during_module_shutdown()) { function = "PHP Shutdown"; } else if (EG(current_execute_data) && + EG(current_execute_data)->func && + ZEND_USER_CODE(EG(current_execute_data)->func->common.type) && EG(current_execute_data)->opline && EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL ) { @@ -844,16 +816,15 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c /* if we still have memory then format the origin */ if (is_function) { - origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params); + origin_len = (int)spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params); } else { - origin_len = spprintf(&origin, 0, "%s", function); + origin_len = (int)spprintf(&origin, 0, "%s", function); } if (PG(html_errors)) { - size_t len; - char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC); + replace_origin = php_escape_html_entities(origin, origin_len, 0, ENT_COMPAT, NULL TSRMLS_CC); efree(origin); - origin = replace; + origin = replace_origin->val; } /* origin and buffer available, so lets come up with the error message */ @@ -869,9 +840,9 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c function++; } if (space[0] == '\0') { - doclen = spprintf(&docref_buf, 0, "function.%s", function); + doclen = (int)spprintf(&docref_buf, 0, "function.%s", function); } else { - doclen = spprintf(&docref_buf, 0, "%s.%s", class_name, function); + doclen = (int)spprintf(&docref_buf, 0, "%s.%s", class_name, function); } while((p = strchr(docref_buf, '_')) != NULL) { *p = '-'; @@ -924,24 +895,32 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c } else { spprintf(&message, 0, "%s: %s", origin, buffer); } - efree(origin); + if (replace_origin) { + zend_string_free(replace_origin); + } else { + efree(origin); + } if (docref_buf) { efree(docref_buf); } - if (PG(track_errors) && module_initialized && - (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) { - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } - if (EG(active_symbol_table)) { - zval *tmp; - ALLOC_INIT_ZVAL(tmp); - ZVAL_STRINGL(tmp, buffer, buffer_len, 1); - zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL); + if (PG(track_errors) && module_initialized && EG(valid_symbol_table) && + (Z_TYPE(EG(user_error_handler)) == IS_UNDEF || !(EG(user_error_handler_error_reporting) & type))) { + zval tmp; + ZVAL_STRINGL(&tmp, buffer, buffer_len); + if (EG(current_execute_data)) { + if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0 TSRMLS_CC) == FAILURE) { + zval_ptr_dtor(&tmp); + } + } else { + zend_hash_str_update_ind(&EG(symbol_table).ht, "php_errormsg", sizeof("php_errormsg")-1, &tmp); } } - efree(buffer); + if (replace_buffer) { + zend_string_free(replace_buffer); + } else { + efree(buffer); + } php_error(type, "%s", message); efree(message); @@ -999,7 +978,7 @@ PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const int buf_len; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL); - buf_len = strlen(buf); + buf_len = (int)strlen(buf); if (buf_len >= 2) { buf[buf_len - 1] = '\0'; buf[buf_len - 2] = '\0'; @@ -1011,7 +990,7 @@ PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const #endif /* {{{ php_html_puts */ -PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC) +PHPAPI void php_html_puts(const char *str, size_t size TSRMLS_DC) { zend_html_puts(str, size TSRMLS_CC); } @@ -1025,7 +1004,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ int buffer_len, display; TSRMLS_FETCH(); - buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args); + buffer_len = (int)vspprintf(&buffer, PG(log_errors_max_len), format, args); /* check for repeated errors to be ignored */ if (PG(ignore_repeated_errors) && PG(last_error_message)) { @@ -1153,17 +1132,16 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) { if (PG(xmlrpc_errors)) { - php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%ld</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno); + php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%pd</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno); } else { char *prepend_string = INI_STR("error_prepend_string"); char *append_string = INI_STR("error_append_string"); if (PG(html_errors)) { if (type == E_ERROR || type == E_PARSE) { - size_t len; - char *buf = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC); - php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buf, error_filename, error_lineno, STR_PRINT(append_string)); - efree(buf); + zend_string *buf = php_escape_html_entities(buffer, buffer_len, 0, ENT_COMPAT, NULL TSRMLS_CC); + php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buf->val, error_filename, error_lineno, STR_PRINT(append_string)); + zend_string_free(buf); } else { php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); } @@ -1173,10 +1151,10 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR ) { #ifdef PHP_WIN32 - fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno); + fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno); fflush(stderr); #else - fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno); + fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno); #endif } else { php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); @@ -1219,10 +1197,19 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ case E_USER_ERROR: { /* new block to allow variable definition */ /* eval() errors do not affect exit_status or response code */ - zend_bool during_eval = (type == E_PARSE) && (EG(current_execute_data) && - EG(current_execute_data)->opline && - EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL && - EG(current_execute_data)->opline->extended_value == ZEND_EVAL); + zend_bool during_eval = 0; + + if (type == E_PARSE) { + zend_execute_data *execute_data = EG(current_execute_data); + + while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) { + execute_data = execute_data->prev_execute_data; + } + + during_eval = (execute_data && + execute_data->opline->opcode == ZEND_INCLUDE_OR_EVAL && + execute_data->opline->extended_value == ZEND_EVAL); + } if (!during_eval) { EG(exit_status) = 255; } @@ -1243,7 +1230,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ CG(parse_error) = 0; } else { /* restore memory limit */ - zend_set_memory_limit(PG(memory_limit)); + zend_set_memory_limit(PG(memory_limit) TSRMLS_CC); efree(buffer); zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC); zend_bailout(); @@ -1260,15 +1247,16 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ return; } - if (PG(track_errors) && module_initialized) { - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } - if (EG(active_symbol_table)) { - zval *tmp; - ALLOC_INIT_ZVAL(tmp); - ZVAL_STRINGL(tmp, buffer, buffer_len, 1); - zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL); + if (PG(track_errors) && module_initialized && EG(valid_symbol_table)) { + zval tmp; + + ZVAL_STRINGL(&tmp, buffer, buffer_len); + if (EG(current_execute_data)) { + if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0 TSRMLS_CC) == FAILURE) { + zval_ptr_dtor(&tmp); + } + } else { + zend_hash_str_update_ind(&EG(symbol_table).ht, "php_errormsg", sizeof("php_errormsg")-1, &tmp); } } @@ -1280,7 +1268,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ */ PHPAPI char *php_get_current_user(TSRMLS_D) { - struct stat *pstat; + zend_stat_t *pstat; if (SG(request_info).current_user) { return SG(request_info).current_user; @@ -1343,21 +1331,24 @@ PHPAPI char *php_get_current_user(TSRMLS_D) Sets the maximum time a script can run */ PHP_FUNCTION(set_time_limit) { - long new_timeout; + zend_long new_timeout; char *new_timeout_str; int new_timeout_strlen; + zend_string *key; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_timeout) == FAILURE) { return; } - new_timeout_strlen = zend_spprintf(&new_timeout_str, 0, "%ld", new_timeout); + new_timeout_strlen = (int)zend_spprintf(&new_timeout_str, 0, ZEND_LONG_FMT, new_timeout); - if (zend_alter_ini_entry_ex("max_execution_time", sizeof("max_execution_time"), new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == SUCCESS) { + key = zend_string_init("max_execution_time", sizeof("max_execution_time")-1, 0); + if (zend_alter_ini_entry_chars_ex(key, new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == SUCCESS) { RETVAL_TRUE; } else { RETVAL_FALSE; } + zend_string_release(key); efree(new_timeout_str); } /* }}} */ @@ -1450,22 +1441,15 @@ static char *php_resolve_path_for_zend(const char *filename, int filename_len TS /* {{{ php_get_configuration_directive_for_zend */ -static int php_get_configuration_directive_for_zend(const char *name, uint name_length, zval *contents) +static zval *php_get_configuration_directive_for_zend(zend_string *name) { - zval *retval = cfg_get_entry(name, name_length); - - if (retval) { - *contents = *retval; - return SUCCESS; - } else { - return FAILURE; - } + return cfg_get_entry_ex(name); } /* }}} */ /* {{{ php_message_handler_for_zend */ -static void php_message_handler_for_zend(long message, const void *data TSRMLS_DC) +static void php_message_handler_for_zend(zend_long message, const void *data TSRMLS_DC) { switch (message) { case ZMSG_FAILED_INCLUDE_FOPEN: @@ -1511,7 +1495,7 @@ static void php_message_handler_for_zend(long message, const void *data TSRMLS_D if (EG(error_reporting) & E_WARNING) { char memory_leak_buf[512]; - snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((zend_uint *) data)); + snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((uint32_t *) data)); # if defined(PHP_WIN32) OutputDebugString(memory_leak_buf); # else @@ -1653,11 +1637,10 @@ int php_request_startup(TSRMLS_D) } if (PG(output_handler) && PG(output_handler)[0]) { - zval *oh; + zval oh; - MAKE_STD_ZVAL(oh); - ZVAL_STRING(oh, PG(output_handler), 1); - php_output_start_user(oh, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); + ZVAL_STRING(&oh, PG(output_handler)); + php_output_start_user(&oh, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); zval_ptr_dtor(&oh); } else if (PG(output_buffering)) { php_output_start_user(NULL, PG(output_buffering) > 1 ? PG(output_buffering) : 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); @@ -1768,9 +1751,7 @@ void php_request_shutdown_for_hook(void *dummy) int i; for (i = 0; i < NUM_TRACK_VARS; i++) { - if (PG(http_globals)[i]) { - zval_ptr_dtor(&PG(http_globals)[i]); - } + zval_ptr_dtor(&PG(http_globals)[i]); } } zend_end_try(); @@ -1808,11 +1789,10 @@ void php_request_shutdown(void *dummy) report_memleaks = PG(report_memleaks); - /* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed + /* EG(current_execute_data) points into nirvana and therefore cannot be safely accessed * inside zend_executor callback functions. */ - EG(opline_ptr) = NULL; - EG(active_op_array) = NULL; + EG(current_execute_data) = NULL; php_deactivate_ticks(TSRMLS_C); @@ -1864,13 +1844,11 @@ void php_request_shutdown(void *dummy) int i; for (i=0; i<NUM_TRACK_VARS; i++) { - if (PG(http_globals)[i]) { - zval_ptr_dtor(&PG(http_globals)[i]); - } + zval_ptr_dtor(&PG(http_globals)[i]); } } zend_end_try(); - /* 7.5 free last error information */ + /* 8. free last error information */ if (PG(last_error_message)) { free(PG(last_error_message)); PG(last_error_message) = NULL; @@ -1880,34 +1858,34 @@ void php_request_shutdown(void *dummy) PG(last_error_file) = NULL; } - /* 7. Shutdown scanner/executor/compiler and restore ini entries */ + /* 9. Shutdown scanner/executor/compiler and restore ini entries */ zend_deactivate(TSRMLS_C); - /* 8. Call all extensions post-RSHUTDOWN functions */ + /* 10. Call all extensions post-RSHUTDOWN functions */ zend_try { zend_post_deactivate_modules(TSRMLS_C); } zend_end_try(); - /* 9. SAPI related shutdown (free stuff) */ + /* 11. SAPI related shutdown (free stuff) */ zend_try { sapi_deactivate(TSRMLS_C); } zend_end_try(); - /* 9.5 free virtual CWD memory */ + /* 12. free virtual CWD memory */ virtual_cwd_deactivate(TSRMLS_C); - /* 10. Destroy stream hashes */ + /* 13. Destroy stream hashes */ zend_try { php_shutdown_stream_hashes(TSRMLS_C); } zend_end_try(); - /* 11. Free Willy (here be crashes) */ + /* 14. Free Willy (here be crashes) */ + zend_interned_strings_restore(TSRMLS_C); zend_try { shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC); } zend_end_try(); - zend_interned_strings_restore(TSRMLS_C); - /* 12. Reset max_execution_time */ + /* 15. Reset max_execution_time */ zend_try { zend_unset_timeout(TSRMLS_C); } zend_end_try(); @@ -1941,7 +1919,7 @@ PHPAPI void php_com_initialize(TSRMLS_D) /* {{{ php_output_wrapper */ -static int php_output_wrapper(const char *str, uint str_length) +static size_t php_output_wrapper(const char *str, size_t str_length) { TSRMLS_FETCH(); return php_output_write(str, str_length TSRMLS_CC); @@ -2047,7 +2025,7 @@ void dummy_invalid_parameter_handler( called = 1; if (function) { if (file) { - len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%d)", function, file, line); + len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%u)", function, file, line); } else { len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function); } @@ -2129,6 +2107,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod zuf.on_timeout = php_on_timeout; zuf.stream_open_function = php_stream_open_for_zend; zuf.vspprintf_function = vspprintf; + zuf.vstrpprintf_function = vstrpprintf; zuf.getenv_function = sapi_getenv; zuf.resolve_path_function = php_resolve_path_for_zend; zend_startup(&zuf, NULL TSRMLS_CC); @@ -2159,7 +2138,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod #endif EG(bailout) = NULL; EG(error_reporting) = E_ALL & ~E_NOTICE; - EG(active_symbol_table) = NULL; PG(header_is_being_sent) = 0; SG(request_info).headers_only = 0; SG(request_info).argv0 = NULL; @@ -2229,8 +2207,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", ZEND_LONG_MAX, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MIN", ZEND_LONG_MIN, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", SIZEOF_ZEND_LONG, CONST_PERSISTENT | CONST_CS); #ifdef PHP_WIN32 REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS); @@ -2299,7 +2278,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod /* load and startup extensions compiled as shared objects (aka DLLs) as requested by php.ini entries - theese are loaded after initialization of internal extensions + these are loaded after initialization of internal extensions as extensions *might* rely on things from ext/standard which is always an internal extension and to be initialized ahead of all other internals @@ -2314,7 +2293,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod /* register additional functions */ if (sapi_module.additional_functions) { - if (zend_hash_find(&module_registry, "standard", sizeof("standard"), (void**)&module)==SUCCESS) { + if ((module = zend_hash_str_find_ptr(&module_registry, "standard", sizeof("standard")-1)) != NULL) { EG(current_module) = module; zend_register_functions(NULL, sapi_module.additional_functions, NULL, MODULE_PERSISTENT TSRMLS_CC); EG(current_module) = NULL; @@ -2326,7 +2305,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod php_disable_classes(TSRMLS_C); /* make core report what it should */ - if (zend_hash_find(&module_registry, "core", sizeof("core"), (void**)&module)==SUCCESS) { + if ((module = zend_hash_str_find_ptr(&module_registry, "core", sizeof("core")-1)) != NULL) { module->version = PHP_VERSION; module->info_func = PHP_MINFO(php_core); } @@ -2350,7 +2329,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod struct { const long error_level; const char *phrase; - const char *directives[16]; /* Remember to change this if the number of directives change */ + const char *directives[17]; /* Remember to change this if the number of directives change */ } directives[2] = { { E_DEPRECATED, @@ -2364,6 +2343,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod "Directive '%s' is no longer available in PHP", { "allow_call_time_pass_reference", + "asp_tags", "define_syslog_variables", "highlight.bg", "magic_quotes_gpc", @@ -2391,7 +2371,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod const char **p = directives[i].directives; while(*p) { - long value; + zend_long value; if (cfg_get_long((char*)*p, &value) == SUCCESS && value) { zend_error(directives[i].error_level, directives[i].phrase, *p); @@ -2522,7 +2502,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC) #ifdef PHP_WIN32 if(primary_file->filename) { - UpdateIniFromRegistry(primary_file->filename TSRMLS_CC); + UpdateIniFromRegistry((char*)primary_file->filename TSRMLS_CC); } #endif @@ -2547,11 +2527,10 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC) primary_file->type != ZEND_HANDLE_FILENAME ) { int realfile_len; - int dummy = 1; if (expand_filepath(primary_file->filename, realfile TSRMLS_CC)) { - realfile_len = strlen(realfile); - zend_hash_add(&EG(included_files), realfile, realfile_len+1, (void *)&dummy, sizeof(int), NULL); + realfile_len = (int)strlen(realfile); + zend_hash_str_add_empty_element(&EG(included_files), realfile, realfile_len); primary_file->opened_path = estrndup(realfile, realfile_len); } } @@ -2602,7 +2581,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC) /* {{{ php_execute_simple_script */ -PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC) +PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval *ret TSRMLS_DC) { char *old_cwd; ALLOCA_FLAG(use_heap) @@ -2615,7 +2594,7 @@ PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret zend_try { #ifdef PHP_WIN32 if(primary_file->filename) { - UpdateIniFromRegistry(primary_file->filename TSRMLS_CC); + UpdateIniFromRegistry((char*)primary_file->filename TSRMLS_CC); } #endif @@ -2660,19 +2639,18 @@ PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC) if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) { char *pass; - char *user; + zend_string *user; - user = php_base64_decode(auth + 6, strlen(auth) - 6, NULL); + user = php_base64_decode(auth + 6, strlen(auth) - 6); if (user) { - pass = strchr(user, ':'); + pass = strchr(user->val, ':'); if (pass) { *pass++ = '\0'; - SG(request_info).auth_user = user; + SG(request_info).auth_user = estrndup(user->val, user->len); SG(request_info).auth_password = estrdup(pass); ret = 0; - } else { - efree(user); - } + } + zend_string_free(user); } } @@ -2720,9 +2698,9 @@ PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC) #ifdef PHP_WIN32 /* {{{ dummy_indent just so that this symbol gets exported... */ -PHPAPI void dummy_indent(void) +PHPAPI void dummy_indent(TSRMLS_D) { - zend_indent(); + zend_indent(TSRMLS_C); } /* }}} */ #endif diff --git a/main/mergesort.c b/main/mergesort.c index 4555e1bc8f..b049e683a9 100644 --- a/main/mergesort.c +++ b/main/mergesort.c @@ -104,7 +104,7 @@ static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const voi */ PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { - register unsigned int i; + register size_t i; register int sense; int big, iflag; register u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; @@ -264,8 +264,8 @@ COPY: b = t; */ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { - int i, length, size2, tmp, sense; - u_char *f1, *f2, *s, *l2, *last, *p2; + size_t i, length, size2, sense; + u_char *f1, *f2, *s, *l2, *last, *p2, tmp; size2 = size*2; if (n <= 5) { @@ -336,7 +336,7 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { u_char *ai, *s, *t, *u, tmp; - int i; + size_t i; for (ai = a+size; --n >= 1; ai += size) for (t = ai; t > a; t -= size) { diff --git a/main/network.c b/main/network.c index f8336442d0..f44cad29a5 100644 --- a/main/network.c +++ b/main/network.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -166,7 +166,7 @@ PHPAPI void php_network_freeaddresses(struct sockaddr **sal) /* {{{ php_network_getaddresses * Returns number of addresses, 0 for none/error */ -PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, char **error_string TSRMLS_DC) +PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string TSRMLS_DC) { struct sockaddr **sap; int n; @@ -212,16 +212,16 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka if ((n = getaddrinfo(host, NULL, &hints, &res))) { if (error_string) { - spprintf(error_string, 0, "php_network_getaddresses: getaddrinfo failed: %s", PHP_GAI_STRERROR(n)); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", *error_string); + *error_string = strpprintf(0, "php_network_getaddresses: getaddrinfo failed: %s", PHP_GAI_STRERROR(n)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", (*error_string)->val); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_network_getaddresses: getaddrinfo failed: %s", PHP_GAI_STRERROR(n)); } return 0; } else if (res == NULL) { if (error_string) { - spprintf(error_string, 0, "php_network_getaddresses: getaddrinfo failed (null result pointer) errno=%d", errno); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", *error_string); + *error_string = strpprintf(0, "php_network_getaddresses: getaddrinfo failed (null result pointer) errno=%d", errno); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", (*error_string)->val); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_network_getaddresses: getaddrinfo failed (null result pointer)"); } @@ -249,8 +249,8 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka host_info = gethostbyname(host); if (host_info == NULL) { if (error_string) { - spprintf(error_string, 0, "php_network_getaddresses: gethostbyname failed. errno=%d", errno); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", *error_string); + error_string = strpprintf(0, "php_network_getaddresses: gethostbyname failed. errno=%d", errno); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", (*error_string)->val); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_network_getaddresses: gethostbyname failed"); } @@ -305,7 +305,7 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, socklen_t addrlen, int asynchronous, struct timeval *timeout, - char **error_string, + zend_string **error_string, int *error_code) { #if HAVE_NON_BLOCKING_CONNECT @@ -326,7 +326,7 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, if (error != EINPROGRESS) { if (error_string) { - *error_string = php_socket_strerror(error, NULL, 0); + *error_string = php_socket_error_str(error); } return -1; @@ -382,7 +382,7 @@ ok: if (error) { ret = -1; if (error_string) { - *error_string = php_socket_strerror(error, NULL, 0); + *error_string = php_socket_error_str(error); } } return ret; @@ -416,13 +416,14 @@ static inline void sub_times(struct timeval a, struct timeval b, struct timeval * */ /* {{{ php_network_bind_socket_to_local_addr */ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned port, - int socktype, char **error_string, int *error_code + int socktype, long sockopts, zend_string **error_string, int *error_code TSRMLS_DC) { int num_addrs, n, err = 0; php_socket_t sock; struct sockaddr **sal, **psal, *sa; socklen_t socklen; + int sockoptval = 1; num_addrs = php_network_getaddresses(host, socktype, &psal, error_string TSRMLS_CC); @@ -464,9 +465,16 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po /* attempt to bind */ #ifdef SO_REUSEADDR - { - int val = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&val, sizeof(val)); + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&sockoptval, sizeof(sockoptval)); +#endif +#ifdef SO_REUSEPORT + if (sockopts & STREAM_SOCKOP_SO_REUSEPORT) { + setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char*)&sockoptval, sizeof(sockoptval)); + } +#endif +#ifdef SO_BROADCAST + if (sockopts & STREAM_SOCKOP_SO_BROADCAST) { + setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&sockoptval, sizeof(sockoptval)); } #endif @@ -487,7 +495,7 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po *error_code = err; } if (error_string) { - *error_string = php_socket_strerror(err, NULL, 0); + *error_string = php_socket_error_str(err); } bound: @@ -499,7 +507,7 @@ bound: } /* }}} */ -PHPAPI int php_network_parse_network_address_with_port(const char *addr, long addrlen, struct sockaddr *sa, socklen_t *sl TSRMLS_DC) +PHPAPI int php_network_parse_network_address_with_port(const char *addr, zend_long addrlen, struct sockaddr *sa, socklen_t *sl TSRMLS_DC) { char *colon; char *tmp; @@ -508,7 +516,7 @@ PHPAPI int php_network_parse_network_address_with_port(const char *addr, long ad struct sockaddr_in *in4 = (struct sockaddr_in*)sa; struct sockaddr **psal; int n; - char *errstr = NULL; + zend_string *errstr = NULL; #if HAVE_IPV6 struct sockaddr_in6 *in6 = (struct sockaddr_in6*)sa; #endif @@ -554,8 +562,8 @@ PHPAPI int php_network_parse_network_address_with_port(const char *addr, long ad if (n == 0) { if (errstr) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to resolve `%s': %s", tmp, errstr); - STR_FREE(errstr); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to resolve `%s': %s", tmp, errstr->val); + zend_string_release(errstr); } goto out; } @@ -581,7 +589,7 @@ PHPAPI int php_network_parse_network_address_with_port(const char *addr, long ad php_network_freeaddresses(psal); out: - STR_FREE(tmp); + efree(tmp); return ret; } @@ -590,7 +598,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( /* input address */ struct sockaddr *sa, socklen_t sl, /* output readable address */ - char **textaddr, long *textaddrlen, + zend_string **textaddr, /* output address */ struct sockaddr **addr, socklen_t *addrlen @@ -613,7 +621,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( /* generally not thread safe, but it *is* thread safe under win32 */ buf = inet_ntoa(((struct sockaddr_in*)sa)->sin_addr); if (buf) { - *textaddrlen = spprintf(textaddr, 0, "%s:%d", + *textaddr = strpprintf(0, "%s:%d", buf, ntohs(((struct sockaddr_in*)sa)->sin_port)); } @@ -623,7 +631,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( case AF_INET6: buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf)); if (buf) { - *textaddrlen = spprintf(textaddr, 0, "%s:%d", + *textaddr = strpprintf(0, "%s:%d", buf, ntohs(((struct sockaddr_in6*)sa)->sin6_port)); } @@ -637,13 +645,10 @@ PHPAPI void php_network_populate_name_from_sockaddr( if (ua->sun_path[0] == '\0') { /* abstract name */ int len = strlen(ua->sun_path + 1) + 1; - *textaddrlen = len; - *textaddr = emalloc(len + 1); - memcpy(*textaddr, ua->sun_path, len); - (*textaddr)[len] = '\0'; + *textaddr = zend_string_init((char*)ua->sun_path, len, 0); } else { - *textaddrlen = strlen(ua->sun_path); - *textaddr = estrndup(ua->sun_path, *textaddrlen); + int len = strlen(ua->sun_path); + *textaddr = zend_string_init((char*)ua->sun_path, len, 0); } } break; @@ -655,7 +660,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( } PHPAPI int php_network_get_peer_name(php_socket_t sock, - char **textaddr, long *textaddrlen, + zend_string **textaddr, struct sockaddr **addr, socklen_t *addrlen TSRMLS_DC) @@ -666,7 +671,7 @@ PHPAPI int php_network_get_peer_name(php_socket_t sock, if (getpeername(sock, (struct sockaddr*)&sa, &sl) == 0) { php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, + textaddr, addr, addrlen TSRMLS_CC); return 0; @@ -675,7 +680,7 @@ PHPAPI int php_network_get_peer_name(php_socket_t sock, } PHPAPI int php_network_get_sock_name(php_socket_t sock, - char **textaddr, long *textaddrlen, + zend_string **textaddr, struct sockaddr **addr, socklen_t *addrlen TSRMLS_DC) @@ -686,7 +691,7 @@ PHPAPI int php_network_get_sock_name(php_socket_t sock, if (getsockname(sock, (struct sockaddr*)&sa, &sl) == 0) { php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, + textaddr, addr, addrlen TSRMLS_CC); return 0; @@ -700,17 +705,17 @@ PHPAPI int php_network_get_sock_name(php_socket_t sock, * using an optional timeout. * Returns the peer address in addr/addrlen (it will emalloc * these, so be sure to efree the result). - * If you specify textaddr/textaddrlen, a text-printable + * If you specify textaddr, a text-printable * version of the address will be emalloc'd and returned. * */ /* {{{ php_network_accept_incoming */ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, - char **textaddr, long *textaddrlen, + zend_string **textaddr, struct sockaddr **addr, socklen_t *addrlen, struct timeval *timeout, - char **error_string, + zend_string **error_string, int *error_code TSRMLS_DC) { @@ -732,7 +737,7 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, if (clisock != SOCK_ERR) { php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, + textaddr, addr, addrlen TSRMLS_CC); } else { @@ -744,7 +749,7 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, *error_code = error; } if (error_string) { - *error_string = php_socket_strerror(error, NULL, 0); + *error_string = php_socket_error_str(error); } return clisock; @@ -761,8 +766,8 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, /* {{{ php_network_connect_socket_to_host */ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short port, - int socktype, int asynchronous, struct timeval *timeout, char **error_string, - int *error_code, char *bindto, unsigned short bindport + int socktype, int asynchronous, struct timeval *timeout, zend_string **error_string, + int *error_code, char *bindto, unsigned short bindport, long sockopts TSRMLS_DC) { int num_addrs, n, fatal = 0; @@ -864,6 +869,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short } } #endif + if (!local_address || bind(sock, local_address, local_address_len)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to bind to '%s:%d', system said: %s", bindto, bindport, strerror(errno)); } @@ -874,10 +880,18 @@ skip_bind: } /* free error string received during previous iteration (if any) */ if (error_string && *error_string) { - efree(*error_string); + zend_string_release(*error_string); *error_string = NULL; } +#ifdef SO_BROADCAST + { + int val = 1; + if (sockopts & STREAM_SOCKOP_SO_BROADCAST) { + setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&val, sizeof(val)); + } + } +#endif n = php_network_connect_socket(sock, sa, socklen, asynchronous, timeout ? &working_timeout : NULL, error_string, error_code); @@ -1029,6 +1043,44 @@ PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize) } /* }}} */ +/* {{{ php_socket_error_str */ +PHPAPI zend_string *php_socket_error_str(long err) +{ +#ifndef PHP_WIN32 + char *errstr; + + errstr = strerror(err); + return zend_string_init(errstr, strlen(errstr), 0); +#else + zend_string *ret; + char *sysbuf; + int free_it = 1; + + if (!FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&sysbuf, + 0, + NULL)) { + free_it = 0; + sysbuf = "Unknown Error"; + } + + ret = zend_string_init(sysbuf, strlen(sysbuf), 0); + + if (free_it) { + LocalFree(sysbuf); + } + + return ret; +#endif +} +/* }}} */ + /* deprecated */ PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const char *persistent_id STREAMS_DC TSRMLS_DC) { @@ -1058,7 +1110,7 @@ PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short p int socktype, struct timeval *timeout, const char *persistent_id STREAMS_DC TSRMLS_DC) { char *res; - long reslen; + zend_long reslen; php_stream *stream; reslen = spprintf(&res, 0, "tcp://%s:%d", host, port); @@ -1071,20 +1123,22 @@ PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short p return stream; } -PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC) +PHPAPI int php_set_sock_blocking(php_socket_t socketd, int block TSRMLS_DC) { int ret = SUCCESS; - int flags; - int myflag = 0; #ifdef PHP_WIN32 + u_long flags; + /* with ioctlsocket, a non-zero sets nonblocking, a zero sets blocking */ flags = !block; if (ioctlsocket(socketd, FIONBIO, &flags) == SOCKET_ERROR) { ret = FAILURE; } #else - flags = fcntl(socketd, F_GETFL); + int myflag = 0; + int flags = fcntl(socketd, F_GETFL); + #ifdef O_NONBLOCK myflag = O_NONBLOCK; /* POSIX version */ #elif defined(O_NDELAY) diff --git a/main/output.c b/main/output.c index 0c7212ac91..c8b41ba1eb 100644 --- a/main/output.c +++ b/main/output.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -55,7 +55,7 @@ static HashTable php_output_handler_reverse_conflicts; static inline int php_output_lock_error(int op TSRMLS_DC); static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC); -static inline php_output_handler *php_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC); +static inline php_output_handler *php_output_handler_init(zend_string *name, size_t chunk_size, int flags TSRMLS_DC); static inline php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context); static inline int php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC); static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry); @@ -86,12 +86,12 @@ static inline void php_output_init_globals(zend_output_globals *G) /* }}} */ /* {{{ stderr/stdout writer if not PHP_OUTPUT_ACTIVATED */ -static int php_output_stdout(const char *str, size_t str_len) +static size_t php_output_stdout(const char *str, size_t str_len) { fwrite(str, 1, str_len, stdout); return str_len; } -static int php_output_stderr(const char *str, size_t str_len) +static size_t php_output_stderr(const char *str, size_t str_len) { fwrite(str, 1, str_len, stderr); /* See http://support.microsoft.com/kb/190351 */ @@ -100,7 +100,7 @@ static int php_output_stderr(const char *str, size_t str_len) #endif return str_len; } -static int (*php_output_direct)(const char *str, size_t str_len) = php_output_stderr; +static size_t (*php_output_direct)(const char *str, size_t str_len) = php_output_stderr; /* }}} */ /* {{{ void php_output_header(TSRMLS_D) */ @@ -109,7 +109,7 @@ static void php_output_header(TSRMLS_D) if (!SG(headers_sent)) { if (!OG(output_start_filename)) { if (zend_is_compiling(TSRMLS_C)) { - OG(output_start_filename) = zend_get_compiled_filename(TSRMLS_C); + OG(output_start_filename) = zend_get_compiled_filename(TSRMLS_C)->val; OG(output_start_lineno) = zend_get_compiled_lineno(TSRMLS_C); } else if (zend_is_executing(TSRMLS_C)) { OG(output_start_filename) = zend_get_executed_filename(TSRMLS_C); @@ -126,14 +126,20 @@ static void php_output_header(TSRMLS_D) } /* }}} */ +static void reverse_conflict_dtor(zval *zv) +{ + HashTable *ht = Z_PTR_P(zv); + zend_hash_destroy(ht); +} + /* {{{ void php_output_startup(void) * Set up module globals and initalize the conflict and reverse conflict hash tables */ PHPAPI void php_output_startup(void) { ZEND_INIT_MODULE_GLOBALS(output, php_output_init_globals, NULL); - zend_hash_init(&php_output_handler_aliases, 0, NULL, NULL, 1); - zend_hash_init(&php_output_handler_conflicts, 0, NULL, NULL, 1); - zend_hash_init(&php_output_handler_reverse_conflicts, 0, NULL, (void (*)(void *)) zend_hash_destroy, 1); + zend_hash_init(&php_output_handler_aliases, 8, NULL, NULL, 1); + zend_hash_init(&php_output_handler_conflicts, 8, NULL, NULL, 1); + zend_hash_init(&php_output_handler_reverse_conflicts, 8, NULL, reverse_conflict_dtor, 1); php_output_direct = php_output_stdout; } /* }}} */ @@ -159,7 +165,7 @@ PHPAPI int php_output_activate(TSRMLS_D) memset(&output_globals, 0, sizeof(zend_output_globals)); #endif - zend_stack_init(&OG(handlers)); + zend_stack_init(&OG(handlers), sizeof(php_output_handler *)); OG(flags) |= PHP_OUTPUT_ACTIVATED; return SUCCESS; @@ -180,7 +186,7 @@ PHPAPI void php_output_deactivate(TSRMLS_D) /* release all output handlers */ if (OG(handlers).elements) { - while (SUCCESS == zend_stack_top(&OG(handlers), (void *) &handler)) { + while ((handler = zend_stack_top(&OG(handlers)))) { php_output_handler_free(handler TSRMLS_CC); zend_stack_del_top(&OG(handlers)); } @@ -232,15 +238,8 @@ PHPAPI int php_output_get_status(TSRMLS_D) /* {{{ int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC) * Unbuffered write */ -PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC) +PHPAPI size_t php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC) { -#if PHP_DEBUG - if (len > UINT_MAX) { - php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; " - "output will be truncated %lu => %lu", - (unsigned long) len, (unsigned long) (len % UINT_MAX)); - } -#endif if (OG(flags) & PHP_OUTPUT_DISABLED) { return 0; } @@ -253,21 +252,14 @@ PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC) /* {{{ int php_output_write(const char *str, size_t len TSRMLS_DC) * Buffered write */ -PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC) +PHPAPI size_t php_output_write(const char *str, size_t len TSRMLS_DC) { -#if PHP_DEBUG - if (len > UINT_MAX) { - php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; " - "output will be truncated %lu => %lu", - (unsigned long) len, (unsigned long) (len % UINT_MAX)); - } -#endif if (OG(flags) & PHP_OUTPUT_DISABLED) { return 0; } if (OG(flags) & PHP_OUTPUT_ACTIVATED) { php_output_op(PHP_OUTPUT_HANDLER_WRITE, str, len TSRMLS_CC); - return (int) len; + return len; } return php_output_direct(str, len); } @@ -285,7 +277,7 @@ PHPAPI int php_output_flush(TSRMLS_D) if (context.out.data && context.out.used) { zend_stack_del_top(&OG(handlers)); php_output_write(context.out.data, context.out.used TSRMLS_CC); - zend_stack_push(&OG(handlers), &OG(active), sizeof(php_output_handler *)); + zend_stack_push(&OG(handlers), &OG(active)); } php_output_context_dtor(&context); return SUCCESS; @@ -385,7 +377,7 @@ PHPAPI int php_output_get_level(TSRMLS_D) PHPAPI int php_output_get_contents(zval *p TSRMLS_DC) { if (OG(active)) { - ZVAL_STRINGL(p, OG(active)->buffer.data, OG(active)->buffer.used, 1); + ZVAL_STRINGL(p, OG(active)->buffer.data, OG(active)->buffer.used); return SUCCESS; } else { ZVAL_NULL(p); @@ -484,9 +476,10 @@ PHPAPI int php_output_start_internal(const char *name, size_t name_len, php_outp * Create a user level output handler */ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, size_t chunk_size, int flags TSRMLS_DC) { - char *handler_name = NULL, *error = NULL; + zend_string *handler_name = NULL; + char *error = NULL; php_output_handler *handler = NULL; - php_output_handler_alias_ctor_t *alias = NULL; + php_output_handler_alias_ctor_t alias = NULL; php_output_handler_user_func_t *user = NULL; switch (Z_TYPE_P(output_handler)) { @@ -495,15 +488,14 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, break; case IS_STRING: if (Z_STRLEN_P(output_handler) && (alias = php_output_handler_alias(Z_STRVAL_P(output_handler), Z_STRLEN_P(output_handler) TSRMLS_CC))) { - handler = (*alias)(Z_STRVAL_P(output_handler), Z_STRLEN_P(output_handler), chunk_size, flags TSRMLS_CC); + handler = alias(Z_STRVAL_P(output_handler), Z_STRLEN_P(output_handler), chunk_size, flags TSRMLS_CC); break; } default: user = ecalloc(1, sizeof(php_output_handler_user_func_t)); if (SUCCESS == zend_fcall_info_init(output_handler, 0, &user->fci, &user->fcc, &handler_name, &error TSRMLS_CC)) { - handler = php_output_handler_init(handler_name, strlen(handler_name), chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER TSRMLS_CC); - Z_ADDREF_P(output_handler); - user->zoh = output_handler; + handler = php_output_handler_init(handler_name, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER TSRMLS_CC); + ZVAL_COPY(&user->zoh, output_handler); handler->func.user = user; } else { efree(user); @@ -513,7 +505,7 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, efree(error); } if (handler_name) { - efree(handler_name); + zend_string_release(handler_name); } } @@ -526,9 +518,11 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; + zend_string *str = zend_string_init(name, name_len, 1); - handler = php_output_handler_init(name, name_len, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL TSRMLS_CC); + handler = php_output_handler_init(str, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL TSRMLS_CC); handler->func.internal = output_handler; + zend_string_release(str); return handler; } @@ -552,30 +546,28 @@ PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC) { HashPosition pos; HashTable *rconflicts; - php_output_handler_conflict_check_t *conflict; + php_output_handler_conflict_check_t conflict; if (php_output_lock_error(PHP_OUTPUT_HANDLER_START TSRMLS_CC) || !handler) { return FAILURE; } - if (SUCCESS == zend_hash_find(&php_output_handler_conflicts, handler->name, handler->name_len+1, (void *) &conflict)) { - if (SUCCESS != (*conflict)(handler->name, handler->name_len TSRMLS_CC)) { + if (NULL != (conflict = zend_hash_find_ptr(&php_output_handler_conflicts, handler->name))) { + if (SUCCESS != conflict(handler->name->val, handler->name->len TSRMLS_CC)) { return FAILURE; } } - if (SUCCESS == zend_hash_find(&php_output_handler_reverse_conflicts, handler->name, handler->name_len+1, (void *) &rconflicts)) { + if (NULL != (rconflicts = zend_hash_find_ptr(&php_output_handler_reverse_conflicts, handler->name))) { for (zend_hash_internal_pointer_reset_ex(rconflicts, &pos); - zend_hash_get_current_data_ex(rconflicts, (void *) &conflict, &pos) == SUCCESS; + (conflict = zend_hash_get_current_data_ptr_ex(rconflicts, &pos)) != NULL; zend_hash_move_forward_ex(rconflicts, &pos) ) { - if (SUCCESS != (*conflict)(handler->name, handler->name_len TSRMLS_CC)) { + if (SUCCESS != conflict(handler->name->val, handler->name->len TSRMLS_CC)) { return FAILURE; } } } - /* zend_stack_push never returns SUCCESS but FAILURE or stack level */ - if (FAILURE == (handler->level = zend_stack_push(&OG(handlers), &handler, sizeof(php_output_handler *)))) { - return FAILURE; - } + /* zend_stack_push returns stack level */ + handler->level = zend_stack_push(&OG(handlers), &handler); OG(active) = handler; return SUCCESS; } @@ -585,14 +577,14 @@ PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC) * Check whether a certain output handler is in use */ PHPAPI int php_output_handler_started(const char *name, size_t name_len TSRMLS_DC) { - php_output_handler ***handlers; + php_output_handler **handlers; int i, count = php_output_get_level(TSRMLS_C); if (count) { - handlers = (php_output_handler ***) zend_stack_base(&OG(handlers)); + handlers = (php_output_handler **) zend_stack_base(&OG(handlers)); for (i = 0; i < count; ++i) { - if (name_len == (*(handlers[i]))->name_len && !memcmp((*(handlers[i]))->name, name, name_len)) { + if (name_len == handlers[i]->name->len && !memcmp(handlers[i]->name->val, name, name_len)) { return 1; } } @@ -626,7 +618,7 @@ PHPAPI int php_output_handler_conflict_register(const char *name, size_t name_le zend_error(E_ERROR, "Cannot register an output handler conflict outside of MINIT"); return FAILURE; } - return zend_hash_update(&php_output_handler_conflicts, name, name_len+1, &check_func, sizeof(php_output_handler_conflict_check_t *), NULL); + return zend_hash_str_update_ptr(&php_output_handler_conflicts, name, name_len, check_func) ? SUCCESS : FAILURE; } /* }}} */ @@ -641,15 +633,15 @@ PHPAPI int php_output_handler_reverse_conflict_register(const char *name, size_t return FAILURE; } - if (SUCCESS == zend_hash_find(&php_output_handler_reverse_conflicts, name, name_len+1, (void *) &rev_ptr)) { - return zend_hash_next_index_insert(rev_ptr, &check_func, sizeof(php_output_handler_conflict_check_t *), NULL); + if (NULL != (rev_ptr = zend_hash_str_find_ptr(&php_output_handler_reverse_conflicts, name, name_len))) { + return zend_hash_next_index_insert_ptr(rev_ptr, check_func) ? SUCCESS : FAILURE; } else { - zend_hash_init(&rev, 1, NULL, NULL, 1); - if (SUCCESS != zend_hash_next_index_insert(&rev, &check_func, sizeof(php_output_handler_conflict_check_t *), NULL)) { + zend_hash_init(&rev, 8, NULL, NULL, 1); + if (NULL == zend_hash_next_index_insert_ptr(&rev, check_func)) { zend_hash_destroy(&rev); return FAILURE; } - if (SUCCESS != zend_hash_update(&php_output_handler_reverse_conflicts, name, name_len+1, &rev, sizeof(HashTable), NULL)) { + if (NULL == zend_hash_str_update_mem(&php_output_handler_reverse_conflicts, name, name_len+1, &rev, sizeof(HashTable))) { zend_hash_destroy(&rev); return FAILURE; } @@ -660,12 +652,9 @@ PHPAPI int php_output_handler_reverse_conflict_register(const char *name, size_t /* {{{ php_output_handler_alias_ctor_t php_output_handler_alias(zval *name TSRMLS_DC) * Get an internal output handler for a user handler if it exists */ -PHPAPI php_output_handler_alias_ctor_t *php_output_handler_alias(const char *name, size_t name_len TSRMLS_DC) +PHPAPI php_output_handler_alias_ctor_t php_output_handler_alias(const char *name, size_t name_len TSRMLS_DC) { - php_output_handler_alias_ctor_t *func = NULL; - - zend_hash_find(&php_output_handler_aliases, name, name_len+1, (void *) &func); - return func; + return zend_hash_str_find_ptr(&php_output_handler_aliases, name, name_len); } /* }}} */ @@ -677,7 +666,7 @@ PHPAPI int php_output_handler_alias_register(const char *name, size_t name_len, zend_error(E_ERROR, "Cannot register an output handler alias outside of MINIT"); return FAILURE; } - return zend_hash_update(&php_output_handler_aliases, name, name_len+1, &func, sizeof(php_output_handler_alias_ctor_t *), NULL); + return zend_hash_str_update_ptr(&php_output_handler_aliases, name, name_len, func) ? SUCCESS : FAILURE; } /* }}} */ @@ -714,8 +703,12 @@ PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSR * Destroy an output handler */ PHPAPI void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC) { - STR_FREE(handler->name); - STR_FREE(handler->buffer.data); + if (handler->name) { + zend_string_release(handler->name); + } + if (handler->buffer.data) { + efree(handler->buffer.data); + } if (handler->flags & PHP_OUTPUT_HANDLER_USER) { zval_ptr_dtor(&handler->func.user->zoh); efree(handler->func.user); @@ -873,13 +866,12 @@ static inline void php_output_context_dtor(php_output_context *context) /* {{{ static php_output_handler *php_output_handler_init(zval *name, size_t chunk_size, int flags TSRMLS_DC) * Allocates and initializes a php_output_handler structure */ -static inline php_output_handler *php_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC) +static inline php_output_handler *php_output_handler_init(zend_string *name, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; handler = ecalloc(1, sizeof(php_output_handler)); - handler->name = estrndup(name, name_len); - handler->name_len = name_len; + handler->name = zend_string_copy(name); handler->size = chunk_size; handler->flags = flags; handler->buffer.size = PHP_OUTPUT_HANDLER_INITBUF_SIZE(chunk_size); @@ -964,23 +956,22 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl OG(running) = handler; if (handler->flags & PHP_OUTPUT_HANDLER_USER) { - zval *retval = NULL, *ob_data, *ob_mode; + zval retval, ob_data, ob_mode; - MAKE_STD_ZVAL(ob_data); - ZVAL_STRINGL(ob_data, handler->buffer.data, handler->buffer.used, 1); - MAKE_STD_ZVAL(ob_mode); - ZVAL_LONG(ob_mode, (long) context->op); + ZVAL_STRINGL(&ob_data, handler->buffer.data, handler->buffer.used); + ZVAL_LONG(&ob_mode, (zend_long) context->op); zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 2, &ob_data, &ob_mode); + zval_ptr_dtor(&ob_data); -#define PHP_OUTPUT_USER_SUCCESS(retval) (retval && !(Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)==0)) +#define PHP_OUTPUT_USER_SUCCESS(retval) ((Z_TYPE(retval) != IS_UNDEF) && !(Z_TYPE(retval) == IS_FALSE)) if (SUCCESS == zend_fcall_info_call(&handler->func.user->fci, &handler->func.user->fcc, &retval, NULL TSRMLS_CC) && PHP_OUTPUT_USER_SUCCESS(retval)) { /* user handler may have returned TRUE */ status = PHP_OUTPUT_HANDLER_NO_DATA; - if (Z_TYPE_P(retval) != IS_BOOL) { + if (Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) { convert_to_string_ex(&retval); - if (Z_STRLEN_P(retval)) { - context->out.data = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); - context->out.used = Z_STRLEN_P(retval); + if (Z_STRLEN(retval)) { + context->out.data = estrndup(Z_STRVAL(retval), Z_STRLEN(retval)); + context->out.used = Z_STRLEN(retval); context->out.free = 1; status = PHP_OUTPUT_HANDLER_SUCCESS; } @@ -991,11 +982,7 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl } zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 0); - zval_ptr_dtor(&ob_data); - zval_ptr_dtor(&ob_mode); - if (retval) { - zval_ptr_dtor(&retval); - } + zval_ptr_dtor(&retval); } else { @@ -1073,7 +1060,7 @@ static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC) if (obh_cnt > 1) { zend_stack_apply_with_argument(&OG(handlers), ZEND_STACK_APPLY_TOPDOWN, php_output_stack_apply_op, &context); - } else if ((SUCCESS == zend_stack_top(&OG(handlers), (void *) &active)) && (!((*active)->flags & PHP_OUTPUT_HANDLER_DISABLED))) { + } else if ((active = zend_stack_top(&OG(handlers))) && (!((*active)->flags & PHP_OUTPUT_HANDLER_DISABLED))) { php_output_handler_op(*active, &context); } else { php_output_context_pass(&context); @@ -1172,7 +1159,7 @@ static int php_output_stack_apply_list(void *h, void *z) php_output_handler *handler = *(php_output_handler **) h; zval *array = (zval *) z; - add_next_index_stringl(array, handler->name, handler->name_len, 1); + add_next_index_str(array, zend_string_copy(handler->name)); return 0; } /* }}} */ @@ -1182,9 +1169,9 @@ static int php_output_stack_apply_list(void *h, void *z) static int php_output_stack_apply_status(void *h, void *z) { php_output_handler *handler = *(php_output_handler **) h; - zval *array = (zval *) z; + zval arr, *array = (zval *) z; - add_next_index_zval(array, php_output_handler_status(handler, NULL)); + add_next_index_zval(array, php_output_handler_status(handler, &arr)); return 0; } @@ -1193,18 +1180,16 @@ static int php_output_stack_apply_status(void *h, void *z) * Returns an array with the status of the output handler */ static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry) { - if (!entry) { - MAKE_STD_ZVAL(entry); - array_init(entry); - } + ZEND_ASSERT(entry != NULL); - add_assoc_stringl(entry, "name", handler->name, handler->name_len, 1); - add_assoc_long(entry, "type", (long) (handler->flags & 0xf)); - add_assoc_long(entry, "flags", (long) handler->flags); - add_assoc_long(entry, "level", (long) handler->level); - add_assoc_long(entry, "chunk_size", (long) handler->size); - add_assoc_long(entry, "buffer_size", (long) handler->buffer.size); - add_assoc_long(entry, "buffer_used", (long) handler->buffer.used); + array_init(entry); + add_assoc_str(entry, "name", zend_string_copy(handler->name)); + add_assoc_long(entry, "type", (zend_long) (handler->flags & 0xf)); + add_assoc_long(entry, "flags", (zend_long) handler->flags); + add_assoc_long(entry, "level", (zend_long) handler->level); + add_assoc_long(entry, "chunk_size", (zend_long) handler->size); + add_assoc_long(entry, "buffer_size", (zend_long) handler->buffer.size); + add_assoc_long(entry, "buffer_used", (zend_long) handler->buffer.used); return entry; } @@ -1224,7 +1209,7 @@ static inline int php_output_stack_pop(int flags TSRMLS_DC) return 0; } else if (!(flags & PHP_OUTPUT_POP_FORCE) && !(orphan->flags & PHP_OUTPUT_HANDLER_REMOVABLE)) { if (!(flags & PHP_OUTPUT_POP_SILENT)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer of %s (%d)", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", orphan->name, orphan->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer of %s (%d)", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", orphan->name->val, orphan->level); } return 0; } else { @@ -1245,7 +1230,7 @@ static inline int php_output_stack_pop(int flags TSRMLS_DC) /* pop it off the stack */ zend_stack_del_top(&OG(handlers)); - if (SUCCESS == zend_stack_top(&OG(handlers), (void *) ¤t)) { + if ((current = zend_stack_top(&OG(handlers)))) { OG(active) = *current; } else { OG(active) = NULL; @@ -1274,7 +1259,7 @@ static int php_output_handler_compat_func(void **handler_context, php_output_con if (func) { char *out_str = NULL; - uint out_len = 0; + size_t out_len = 0; func(output_context->in.data, output_context->in.used, &out_str, &out_len, output_context->op TSRMLS_CC); @@ -1318,8 +1303,8 @@ static int php_output_handler_devnull_func(void **handler_context, php_output_co PHP_FUNCTION(ob_start) { zval *output_handler = NULL; - long chunk_size = 0; - long flags = PHP_OUTPUT_HANDLER_STDFLAGS; + zend_long chunk_size = 0; + zend_long flags = PHP_OUTPUT_HANDLER_STDFLAGS; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/ll", &output_handler, &chunk_size, &flags) == FAILURE) { return; @@ -1351,7 +1336,7 @@ PHP_FUNCTION(ob_flush) } if (SUCCESS != php_output_flush(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer of %s (%d)", OG(active)->name->val, OG(active)->level); RETURN_FALSE; } RETURN_TRUE; @@ -1372,7 +1357,7 @@ PHP_FUNCTION(ob_clean) } if (SUCCESS != php_output_clean(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name->val, OG(active)->level); RETURN_FALSE; } RETURN_TRUE; @@ -1427,7 +1412,7 @@ PHP_FUNCTION(ob_get_flush) } if (SUCCESS != php_output_end(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name->val, OG(active)->level); } } /* }}} */ @@ -1450,7 +1435,7 @@ PHP_FUNCTION(ob_get_clean) } if (SUCCESS != php_output_discard(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name->val, OG(active)->level); } } /* }}} */ @@ -1523,13 +1508,13 @@ PHP_FUNCTION(ob_get_status) return; } - array_init(return_value); - if (!OG(active)) { + array_init(return_value); return; } if (full_status) { + array_init(return_value); zend_stack_apply_with_argument(&OG(handlers), ZEND_STACK_APPLY_BOTTOMUP, php_output_stack_apply_status, return_value); } else { php_output_handler_status(OG(active), return_value); @@ -1541,7 +1526,7 @@ PHP_FUNCTION(ob_get_status) Turn implicit flush on/off and is equivalent to calling flush() after every output call */ PHP_FUNCTION(ob_implicit_flush) { - long flag = 1; + zend_long flag = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) { return; @@ -1568,7 +1553,7 @@ PHP_FUNCTION(output_reset_rewrite_vars) PHP_FUNCTION(output_add_rewrite_var) { char *name, *value; - int name_len, value_len; + size_t name_len, value_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &value, &value_len) == FAILURE) { return; diff --git a/main/php.h b/main/php.h index 4330479d50..2a683e1924 100644 --- a/main/php.h +++ b/main/php.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -26,7 +26,7 @@ #include <dmalloc.h> #endif -#define PHP_API_VERSION 20131106 +#define PHP_API_VERSION 20131218 #define PHP_HAVE_STREAMS #define YYDEBUG 0 #define PHP_DEFAULT_CHARSET "UTF-8" @@ -280,8 +280,8 @@ ssize_t pread(int, void *, size_t, off64_t); BEGIN_EXTERN_C() void phperror(char *error); -PHPAPI int php_write(void *buf, uint size TSRMLS_DC); -PHPAPI int php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, +PHPAPI size_t php_write(void *buf, size_t size TSRMLS_DC); +PHPAPI size_t php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2); PHPAPI int php_get_module_initialized(void); PHPAPI void php_log_err(char *log_message TSRMLS_DC); @@ -434,7 +434,7 @@ END_EXTERN_C() #else /* ! (CRAY || __arm) */ #define XtOffset(p_type, field) \ - ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) + ((zend_long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) #endif /* !CRAY */ #endif /* ! XtOffset */ diff --git a/main/php_compat.h b/main/php_compat.h index 20951ba427..5e6af03c59 100644 --- a/main/php_compat.h +++ b/main/php_compat.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_content_types.c b/main/php_content_types.c index ca47e15285..8765a507bc 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -33,19 +33,6 @@ static sapi_post_entry php_post_entries[] = { }; /* }}} */ -static zend_bool populate_raw_post_data(TSRMLS_D) -{ - if (!SG(request_info).request_body) { - return (zend_bool) 0; - } - - if (!PG(always_populate_raw_post_data)) { - return (zend_bool) !SG(request_info).post_entry; - } - - return (zend_bool) (PG(always_populate_raw_post_data) > 0); -} - /* {{{ SAPI_POST_READER_FUNC */ SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) @@ -55,29 +42,6 @@ SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) /* no post handler registered, so we just swallow the data */ sapi_read_standard_form_data(TSRMLS_C); } - - if (populate_raw_post_data(TSRMLS_C)) { - size_t length; - char *data = NULL; - - php_stream_rewind(SG(request_info).request_body); - length = php_stream_copy_to_mem(SG(request_info).request_body, &data, PHP_STREAM_COPY_ALL, 0); - php_stream_rewind(SG(request_info).request_body); - - if (length > INT_MAX) { - sapi_module.sapi_error(E_WARNING, - "HTTP_RAW_POST_DATA truncated from %lu to %d bytes", - (unsigned long) length, INT_MAX); - length = INT_MAX; - } - SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, length); - - sapi_module.sapi_error(E_DEPRECATED, - "Automatically populating $HTTP_RAW_POST_DATA is deprecated and " - "will be removed in a future version. To avoid this warning set " - "'always_populate_raw_post_data' to '-1' in php.ini and use the " - "php://input stream instead."); - } } } /* }}} */ diff --git a/main/php_content_types.h b/main/php_content_types.h index ed5346c843..0a49d1e2cd 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_getopt.h b/main/php_getopt.h index f536ac8a96..8f70181786 100644 --- a/main/php_getopt.h +++ b/main/php_getopt.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_globals.h b/main/php_globals.h index e135d61865..a60efe69de 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -56,7 +56,7 @@ typedef struct _arg_separators { struct _php_core_globals { zend_bool implicit_flush; - long output_buffering; + zend_long output_buffering; zend_bool sql_safe_mode; zend_bool enable_dl; @@ -64,16 +64,16 @@ struct _php_core_globals { char *output_handler; char *unserialize_callback_func; - long serialize_precision; + zend_long serialize_precision; - long memory_limit; - long max_input_time; + zend_long memory_limit; + zend_long max_input_time; zend_bool track_errors; zend_bool display_errors; zend_bool display_startup_errors; zend_bool log_errors; - long log_errors_max_len; + zend_long log_errors_max_len; zend_bool ignore_repeated_errors; zend_bool ignore_repeated_source; zend_bool report_memleaks; @@ -88,7 +88,7 @@ struct _php_core_globals { char *sys_temp_dir; char *upload_tmp_dir; - long upload_max_filesize; + zend_long upload_max_filesize; char *error_append_string; char *error_prepend_string; @@ -113,7 +113,7 @@ struct _php_core_globals { zend_llist tick_functions; - zval *http_globals[6]; + zval http_globals[6]; zend_bool expose_php; @@ -126,7 +126,7 @@ struct _php_core_globals { zend_bool html_errors; zend_bool xmlrpc_errors; - long xmlrpc_error_number; + zend_long xmlrpc_error_number; zend_bool activated_auto_globals[8]; @@ -135,7 +135,6 @@ struct _php_core_globals { zend_bool during_request_startup; zend_bool allow_url_fopen; zend_bool enable_post_data_reading; - signed char always_populate_raw_post_data; zend_bool report_zend_debug; int last_error_type; @@ -150,12 +149,12 @@ struct _php_core_globals { #ifdef PHP_WIN32 zend_bool com_initialized; #endif - long max_input_nesting_level; - long max_input_vars; + zend_long max_input_nesting_level; + zend_long max_input_vars; zend_bool in_user_include; char *user_ini_filename; - long user_ini_cache_ttl; + zend_long user_ini_cache_ttl; char *request_order; diff --git a/main/php_ini.c b/main/php_ini.c index e20ba4ba73..5303bf77ec 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -80,12 +80,13 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type TSRMLS_DC) ini_entry->displayer(ini_entry, type); } else { char *display_string; - uint display_string_length, esc_html=0; + size_t display_string_length; + int esc_html=0; if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - if (ini_entry->orig_value && ini_entry->orig_value[0]) { - display_string = ini_entry->orig_value; - display_string_length = ini_entry->orig_value_length; + if (ini_entry->orig_value && ini_entry->orig_value->val[0]) { + display_string = ini_entry->orig_value->val; + display_string_length = ini_entry->orig_value->len; esc_html = !sapi_module.phpinfo_as_text; } else { if (!sapi_module.phpinfo_as_text) { @@ -96,9 +97,9 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type TSRMLS_DC) display_string_length = sizeof("no value") - 1; } } - } else if (ini_entry->value && ini_entry->value[0]) { - display_string = ini_entry->value; - display_string_length = ini_entry->value_length; + } else if (ini_entry->value && ini_entry->value->val[0]) { + display_string = ini_entry->value->val; + display_string_length = ini_entry->value->len; esc_html = !sapi_module.phpinfo_as_text; } else { if (!sapi_module.phpinfo_as_text) { @@ -121,22 +122,25 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type TSRMLS_DC) /* {{{ php_ini_displayer */ -static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC) +static int php_ini_displayer(zval *el, void *arg TSRMLS_DC) { + zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el); + int module_number = *(int *)arg; + if (ini_entry->module_number != module_number) { return 0; } if (!sapi_module.phpinfo_as_text) { PUTS("<tr>"); PUTS("<td class=\"e\">"); - PHPWRITE(ini_entry->name, ini_entry->name_length - 1); + PHPWRITE(ini_entry->name->val, ini_entry->name->len); PUTS("</td><td class=\"v\">"); php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE TSRMLS_CC); PUTS("</td><td class=\"v\">"); php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG TSRMLS_CC); PUTS("</td></tr>\n"); } else { - PHPWRITE(ini_entry->name, ini_entry->name_length - 1); + PHPWRITE(ini_entry->name->val, ini_entry->name->len); PUTS(" => "); php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE TSRMLS_CC); PUTS(" => "); @@ -149,10 +153,12 @@ static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS /* {{{ php_ini_available */ -static int php_ini_available(zend_ini_entry *ini_entry, int *module_number_available TSRMLS_DC) +static int php_ini_available(zval *el, void *arg TSRMLS_DC) { - if (ini_entry->module_number == *module_number_available) { - *module_number_available = -1; + zend_ini_entry *ini_entry = (zend_ini_entry *)Z_PTR_P(el); + int *module_number_available = (int *)arg; + if (ini_entry->module_number == *(int *)module_number_available) { + *(int *)module_number_available = -1; return ZEND_HASH_APPLY_STOP; } else { return ZEND_HASH_APPLY_KEEP; @@ -173,11 +179,11 @@ PHPAPI void display_ini_entries(zend_module_entry *module) module_number = 0; } module_number_available = module_number; - zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_available, &module_number_available TSRMLS_CC); + zend_hash_apply_with_argument(EG(ini_directives), php_ini_available, &module_number_available TSRMLS_CC); if (module_number_available == -1) { php_info_print_table_start(); php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); - zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (zend_intptr_t) module_number TSRMLS_CC); + zend_hash_apply_with_argument(EG(ini_directives), php_ini_displayer, (void *)&module_number TSRMLS_CC); php_info_print_table_end(); } } @@ -193,9 +199,9 @@ PHPAPI void config_zval_dtor(zval *zvalue) { if (Z_TYPE_P(zvalue) == IS_ARRAY) { zend_hash_destroy(Z_ARRVAL_P(zvalue)); - free(Z_ARRVAL_P(zvalue)); + free(Z_ARR_P(zvalue)); } else if (Z_TYPE_P(zvalue) == IS_STRING) { - free(Z_STRVAL_P(zvalue)); + zend_string_release(Z_STR_P(zvalue)); } } /* Reset / free active_ini_sectin global */ @@ -237,14 +243,14 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t /* All other entries are added into either configuration_hash or active ini section array */ } else { /* Store in active hash */ - zend_hash_update(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry); - Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)); + entry = zend_hash_update(active_hash, Z_STR_P(arg1), arg2); + Z_STR_P(entry) = zend_string_dup(Z_STR_P(entry), 1); } } break; case ZEND_INI_PARSER_POP_ENTRY: { - zval *option_arr; + zval option_arr; zval *find_arr; if (!arg2) { @@ -255,23 +261,19 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t /* fprintf(stdout, "ZEND_INI_PARSER_POP_ENTRY: %s[%s] = %s\n",Z_STRVAL_P(arg1), Z_STRVAL_P(arg3), Z_STRVAL_P(arg2)); */ /* If option not found in hash or is not an array -> create array, otherwise add to existing array */ - if (zend_hash_find(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, (void **) &find_arr) == FAILURE || Z_TYPE_P(find_arr) != IS_ARRAY) { - option_arr = (zval *) pemalloc(sizeof(zval), 1); - INIT_PZVAL(option_arr); - Z_TYPE_P(option_arr) = IS_ARRAY; - Z_ARRVAL_P(option_arr) = (HashTable *) pemalloc(sizeof(HashTable), 1); - zend_hash_init(Z_ARRVAL_P(option_arr), 0, NULL, (dtor_func_t) config_zval_dtor, 1); - zend_hash_update(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, option_arr, sizeof(zval), (void **) &find_arr); - free(option_arr); + if ((find_arr = zend_hash_find(active_hash, Z_STR_P(arg1))) == NULL || Z_TYPE_P(find_arr) != IS_ARRAY) { + ZVAL_NEW_PERSISTENT_ARR(&option_arr); + zend_hash_init(Z_ARRVAL(option_arr), 8, NULL, config_zval_dtor, 1); + find_arr = zend_hash_update(active_hash, Z_STR_P(arg1), &option_arr); } /* arg3 is possible option offset name */ if (arg3 && Z_STRLEN_P(arg3) > 0) { - zend_symtable_update(Z_ARRVAL_P(find_arr), Z_STRVAL_P(arg3), Z_STRLEN_P(arg3) + 1, arg2, sizeof(zval), (void **) &entry); + entry = zend_symtable_update(Z_ARRVAL_P(find_arr), Z_STR_P(arg3), arg2); } else { - zend_hash_next_index_insert(Z_ARRVAL_P(find_arr), arg2, sizeof(zval), (void **) &entry); + entry = zend_hash_next_index_insert(Z_ARRVAL_P(find_arr), arg2); } - Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)); + Z_STR_P(entry) = zend_string_dup(Z_STR_P(entry), 1); } break; @@ -280,7 +282,7 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t /* fprintf(stdout, "ZEND_INI_PARSER_SECTION: %s\n",Z_STRVAL_P(arg1)); */ char *key = NULL; - uint key_len; + size_t key_len; /* PATH sections */ if (!strncasecmp(Z_STRVAL_P(arg1), "PATH", sizeof("PATH") - 1)) { @@ -324,16 +326,12 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t } /* Search for existing entry and if it does not exist create one */ - if (zend_hash_find(target_hash, key, key_len + 1, (void **) &entry) == FAILURE) { - zval *section_arr; - - section_arr = (zval *) pemalloc(sizeof(zval), 1); - INIT_PZVAL(section_arr); - Z_TYPE_P(section_arr) = IS_ARRAY; - Z_ARRVAL_P(section_arr) = (HashTable *) pemalloc(sizeof(HashTable), 1); - zend_hash_init(Z_ARRVAL_P(section_arr), 0, NULL, (dtor_func_t) config_zval_dtor, 1); - zend_hash_update(target_hash, key, key_len + 1, section_arr, sizeof(zval), (void **) &entry); - free(section_arr); + if ((entry = zend_hash_str_find(target_hash, key, key_len)) == NULL) { + zval section_arr; + + ZVAL_NEW_PERSISTENT_ARR(§ion_arr); + zend_hash_init(Z_ARRVAL(section_arr), 8, NULL, (dtor_func_t) config_zval_dtor, 1); + entry = zend_hash_str_update(target_hash, key, key_len, §ion_arr); } active_ini_hash = Z_ARRVAL_P(entry); } @@ -358,21 +356,21 @@ static void php_load_php_extension_cb(void *arg TSRMLS_DC) static void php_load_zend_extension_cb(void *arg TSRMLS_DC) { char *filename = *((char **) arg); - int length = strlen(filename); + const int length = (int)strlen(filename); if (IS_ABSOLUTE_PATH(filename, length)) { - zend_load_extension(filename); + zend_load_extension(filename TSRMLS_CC); } else { char *libpath; char *extension_dir = INI_STR("extension_dir"); - int extension_dir_len = strlen(extension_dir); + int extension_dir_len = (int)strlen(extension_dir); if (IS_SLASH(extension_dir[extension_dir_len-1])) { spprintf(&libpath, 0, "%s%s", extension_dir, filename); } else { spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); } - zend_load_extension(libpath); + zend_load_extension(libpath TSRMLS_CC); efree(libpath); } } @@ -389,9 +387,7 @@ int php_init_config(TSRMLS_D) int free_ini_search_path = 0; zend_file_handle fh; - if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) config_zval_dtor, 1) == FAILURE) { - return FAILURE; - } + zend_hash_init(&configuration_hash, 8, NULL, config_zval_dtor, 1); if (sapi_module.ini_defaults) { sapi_module.ini_defaults(&configuration_hash); @@ -454,7 +450,7 @@ int php_init_config(TSRMLS_D) * Prepare search path */ - search_path_size = MAXPATHLEN * 4 + strlen(env_location) + 3 + 1; + search_path_size = MAXPATHLEN * 4 + (int)strlen(env_location) + 3 + 1; php_ini_search_path = (char *) emalloc(search_path_size); free_ini_search_path = 1; php_ini_search_path[0] = 0; @@ -550,7 +546,7 @@ int php_init_config(TSRMLS_D) /* Check if php_ini_file_name is a file and can be opened */ if (php_ini_file_name && php_ini_file_name[0]) { - struct stat statbuf; + zend_stat_t statbuf; if (!VCWD_STAT(php_ini_file_name, &statbuf)) { if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) { @@ -598,12 +594,8 @@ int php_init_config(TSRMLS_D) { zval tmp; - Z_STRLEN(tmp) = strlen(fh.filename); - Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp)); - Z_TYPE(tmp) = IS_STRING; - Z_SET_REFCOUNT(tmp, 0); - - zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL); + ZVAL_NEW_STR(&tmp, zend_string_init(fh.filename, strlen(fh.filename), 1)); + zend_hash_str_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path")-1, &tmp); if (php_ini_opened_path) { efree(php_ini_opened_path); } @@ -617,13 +609,13 @@ int php_init_config(TSRMLS_D) /* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */ php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR; } - php_ini_scanned_path_len = strlen(php_ini_scanned_path); + php_ini_scanned_path_len = (int)strlen(php_ini_scanned_path); /* Scan and parse any .ini files found in scan path if path not empty. */ if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) { struct dirent **namelist; int ndir, i; - struct stat sb; + zend_stat_t sb; char ini_file[MAXPATHLEN]; char *p; zend_file_handle fh2; @@ -647,7 +639,7 @@ int php_init_config(TSRMLS_D) to allow "/foo/phd.d:" or ":/foo/php.d" */ debpath = PHP_CONFIG_FILE_SCAN_DIR; } - lenpath = strlen(debpath); + lenpath = (int)strlen(debpath); if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_alphasort)) > 0) { @@ -674,7 +666,7 @@ int php_init_config(TSRMLS_D) if (zend_parse_ini_file(&fh2, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC) == SUCCESS) { /* Here, add it to the list of ini files read */ - l = strlen(ini_file); + l = (int)strlen(ini_file); total_l += l + 2; p = estrndup(ini_file, l); zend_llist_add_element(&scanned_ini_list, &p); @@ -690,7 +682,7 @@ int php_init_config(TSRMLS_D) efree(bufpath); if (total_l) { - int php_ini_scanned_files_len = (php_ini_scanned_files) ? strlen(php_ini_scanned_files) + 1 : 0; + int php_ini_scanned_files_len = (php_ini_scanned_files) ? (int)strlen(php_ini_scanned_files) + 1 : 0; php_ini_scanned_files = (char *) realloc(php_ini_scanned_files, php_ini_scanned_files_len + total_l + 1); if (!php_ini_scanned_files_len) { *php_ini_scanned_files = '\0'; @@ -753,7 +745,7 @@ void php_ini_register_extensions(TSRMLS_D) */ PHPAPI int php_parse_user_ini_file(const char *dirname, char *ini_filename, HashTable *target_hash TSRMLS_DC) { - struct stat sb; + zend_stat_t sb; char ini_file[MAXPATHLEN]; zend_file_handle fh; @@ -785,18 +777,17 @@ PHPAPI int php_parse_user_ini_file(const char *dirname, char *ini_filename, Hash */ PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC) { - char *str; + zend_string *str; zval *data; - uint str_len; - ulong num_index; + zend_ulong num_index; /* Walk through config hash and alter matching ini entries using the values found in the hash */ for (zend_hash_internal_pointer_reset(source_hash); - zend_hash_get_current_key_ex(source_hash, &str, &str_len, &num_index, 0, NULL) == HASH_KEY_IS_STRING; + zend_hash_get_current_key(source_hash, &str, &num_index, 0) == HASH_KEY_IS_STRING; zend_hash_move_forward(source_hash) ) { - zend_hash_get_current_data(source_hash, (void **) &data); - zend_alter_ini_entry_ex(str, str_len, Z_STRVAL_P(data), Z_STRLEN_P(data), modify_type, stage, 0 TSRMLS_CC); + data = zend_hash_get_current_data(source_hash); + zend_alter_ini_entry_ex(str, Z_STR_P(data), modify_type, stage, 0 TSRMLS_CC); } } /* }}} */ @@ -811,7 +802,7 @@ PHPAPI int php_ini_has_per_dir_config(void) /* {{{ php_ini_activate_per_dir_config */ -PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC) +PHPAPI void php_ini_activate_per_dir_config(char *path, size_t path_len TSRMLS_DC) { zval *tmp2; char *ptr; @@ -842,7 +833,7 @@ PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC) while ((ptr = strchr(ptr, '/')) != NULL) { *ptr = 0; /* Search for source array matching the path from configuration_hash */ - if (zend_hash_find(&configuration_hash, path, strlen(path) + 1, (void **) &tmp2) == SUCCESS) { + if ((tmp2 = zend_hash_str_find(&configuration_hash, path, strlen(path))) != NULL) { php_ini_activate_config(Z_ARRVAL_P(tmp2), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC); } *ptr = '/'; @@ -862,13 +853,13 @@ PHPAPI int php_ini_has_per_host_config(void) /* {{{ php_ini_activate_per_host_config */ -PHPAPI void php_ini_activate_per_host_config(const char *host, uint host_len TSRMLS_DC) +PHPAPI void php_ini_activate_per_host_config(const char *host, size_t host_len TSRMLS_DC) { zval *tmp; if (has_per_host_config && host && host_len) { /* Search for source array matching the host from configuration_hash */ - if (zend_hash_find(&configuration_hash, host, host_len, (void **) &tmp) == SUCCESS) { + if ((tmp = zend_hash_str_find(&configuration_hash, host, host_len)) != NULL) { php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC); } } @@ -877,30 +868,31 @@ PHPAPI void php_ini_activate_per_host_config(const char *host, uint host_len TSR /* {{{ cfg_get_entry */ -PHPAPI zval *cfg_get_entry(const char *name, uint name_length) +PHPAPI zval *cfg_get_entry_ex(zend_string *name) { - zval *tmp; + return zend_hash_find(&configuration_hash, name); +} +/* }}} */ - if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) { - return tmp; - } else { - return NULL; - } +/* {{{ cfg_get_entry + */ +PHPAPI zval *cfg_get_entry(const char *name, size_t name_length) +{ + return zend_hash_str_find(&configuration_hash, name, name_length); } /* }}} */ /* {{{ cfg_get_long */ -PHPAPI int cfg_get_long(const char *varname, long *result) +PHPAPI int cfg_get_long(const char *varname, zend_long *result) { zval *tmp, var; - if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) { + if ((tmp = zend_hash_str_find(&configuration_hash, varname, strlen(varname))) == NULL) { *result = 0; return FAILURE; } - var = *tmp; - zval_copy_ctor(&var); + ZVAL_DUP(&var, tmp); convert_to_long(&var); *result = Z_LVAL(var); return SUCCESS; @@ -913,12 +905,11 @@ PHPAPI int cfg_get_double(const char *varname, double *result) { zval *tmp, var; - if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) { + if ((tmp = zend_hash_str_find(&configuration_hash, varname, strlen(varname))) == NULL) { *result = (double) 0; return FAILURE; } - var = *tmp; - zval_copy_ctor(&var); + ZVAL_DUP(&var, tmp); convert_to_double(&var); *result = Z_DVAL(var); return SUCCESS; @@ -931,7 +922,7 @@ PHPAPI int cfg_get_string(const char *varname, char **result) { zval *tmp; - if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) { + if ((tmp = zend_hash_str_find(&configuration_hash, varname, strlen(varname))) == NULL) { *result = NULL; return FAILURE; } diff --git a/main/php_ini.h b/main/php_ini.h index 4159e7591f..7022507f51 100644 --- a/main/php_ini.h +++ b/main/php_ini.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -28,16 +28,17 @@ PHPAPI void config_zval_dtor(zval *zvalue); int php_init_config(TSRMLS_D); int php_shutdown_config(void); void php_ini_register_extensions(TSRMLS_D); -PHPAPI zval *cfg_get_entry(const char *name, uint name_length); -PHPAPI int cfg_get_long(const char *varname, long *result); +PHPAPI zval *cfg_get_entry_ex(zend_string *name); +PHPAPI zval *cfg_get_entry(const char *name, size_t name_length); +PHPAPI int cfg_get_long(const char *varname, zend_long *result); PHPAPI int cfg_get_double(const char *varname, double *result); PHPAPI int cfg_get_string(const char *varname, char **result); PHPAPI int php_parse_user_ini_file(const char *dirname, char *ini_filename, HashTable *target_hash TSRMLS_DC); PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC); PHPAPI int php_ini_has_per_dir_config(void); PHPAPI int php_ini_has_per_host_config(void); -PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC); -PHPAPI void php_ini_activate_per_host_config(const char *host, uint host_len TSRMLS_DC); +PHPAPI void php_ini_activate_per_dir_config(char *path, size_t path_len TSRMLS_DC); +PHPAPI void php_ini_activate_per_host_config(const char *host, size_t host_len TSRMLS_DC); PHPAPI HashTable* php_ini_get_configuration_hash(void); END_EXTERN_C() diff --git a/main/php_main.h b/main/php_main.h index 03c89c5d6f..94a6299fc3 100644 --- a/main/php_main.h +++ b/main/php_main.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -40,14 +40,14 @@ PHPAPI void php_request_shutdown_for_hook(void *dummy); PHPAPI int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC); PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC); -PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC); +PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval *ret TSRMLS_DC); PHPAPI int php_handle_special_queries(TSRMLS_D); PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC); PHPAPI void php_handle_aborted_connection(void); PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC); -PHPAPI void php_html_puts(const char *str, uint siz TSRMLS_DC); +PHPAPI void php_html_puts(const char *str, size_t siz TSRMLS_DC); PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC); /* environment module */ diff --git a/main/php_memory_streams.h b/main/php_memory_streams.h index 229ed1902e..a7823817bc 100644 --- a/main/php_memory_streams.h +++ b/main/php_memory_streams.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_network.h b/main/php_network.h index d69bba308a..b0b1787ea5 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -63,6 +63,7 @@ * Also works sensibly for win32 */ BEGIN_EXTERN_C() PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize); +PHPAPI zend_string *php_socket_error_str(long err); END_EXTERN_C() #ifdef HAVE_NETINET_IN_H @@ -105,6 +106,11 @@ typedef int php_socket_t; # define SOCK_RECV_ERR -1 #endif +#define STREAM_SOCKOP_NONE 1 << 0 +#define STREAM_SOCKOP_SO_REUSEPORT 1 << 1 +#define STREAM_SOCKOP_SO_BROADCAST 1 << 2 + + /* uncomment this to debug poll(2) emulation on systems that have poll(2) */ /* #define PHP_USE_POLL_2_EMULATION 1 */ @@ -224,12 +230,12 @@ typedef struct { #endif BEGIN_EXTERN_C() -PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, char **error_string TSRMLS_DC); +PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string TSRMLS_DC); PHPAPI void php_network_freeaddresses(struct sockaddr **sal); PHPAPI php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short port, - int socktype, int asynchronous, struct timeval *timeout, char **error_string, - int *error_code, char *bindto, unsigned short bindport + int socktype, int asynchronous, struct timeval *timeout, zend_string **error_string, + int *error_code, char *bindto, unsigned short bindport, long sockopts TSRMLS_DC); PHPAPI int php_network_connect_socket(php_socket_t sockfd, @@ -237,33 +243,33 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, socklen_t addrlen, int asynchronous, struct timeval *timeout, - char **error_string, + zend_string **error_string, int *error_code); #define php_connect_nonb(sock, addr, addrlen, timeout) \ php_network_connect_socket((sock), (addr), (addrlen), 0, (timeout), NULL, NULL) PHPAPI php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned port, - int socktype, char **error_string, int *error_code + int socktype, long sockopts, zend_string **error_string, int *error_code TSRMLS_DC); PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, - char **textaddr, long *textaddrlen, + zend_string **textaddr, struct sockaddr **addr, socklen_t *addrlen, struct timeval *timeout, - char **error_string, + zend_string **error_string, int *error_code TSRMLS_DC); PHPAPI int php_network_get_sock_name(php_socket_t sock, - char **textaddr, long *textaddrlen, + zend_string **textaddr, struct sockaddr **addr, socklen_t *addrlen TSRMLS_DC); PHPAPI int php_network_get_peer_name(php_socket_t sock, - char **textaddr, long *textaddrlen, + zend_string **textaddr, struct sockaddr **addr, socklen_t *addrlen TSRMLS_DC); @@ -293,14 +299,14 @@ PHPAPI void php_network_populate_name_from_sockaddr( /* input address */ struct sockaddr *sa, socklen_t sl, /* output readable address */ - char **textaddr, long *textaddrlen, + zend_string **textaddr, /* output address */ struct sockaddr **addr, socklen_t *addrlen TSRMLS_DC); PHPAPI int php_network_parse_network_address_with_port(const char *addr, - long addrlen, struct sockaddr *sa, socklen_t *sl TSRMLS_DC); + zend_long addrlen, struct sockaddr *sa, socklen_t *sl TSRMLS_DC); END_EXTERN_C() #define php_stream_sock_open_from_socket(socket, persistent) _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_CC TSRMLS_CC) diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c index ebe5350ef2..955f0d26e1 100644 --- a/main/php_open_temporary_file.c +++ b/main/php_open_temporary_file.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -125,7 +125,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char ** } new_state.cwd = estrdup(cwd); - new_state.cwd_length = strlen(cwd); + new_state.cwd_length = (int)strlen(cwd); if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)) { efree(new_state.cwd); @@ -200,7 +200,7 @@ PHPAPI const char* php_get_temporary_directory(TSRMLS_D) { char *sys_temp_dir = PG(sys_temp_dir); if (sys_temp_dir) { - int len = strlen(sys_temp_dir); + int len = (int)strlen(sys_temp_dir); if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) { temporary_directory = zend_strndup(sys_temp_dir, len - 1); return temporary_directory; diff --git a/main/php_open_temporary_file.h b/main/php_open_temporary_file.h index 873bffcb0a..a11cb79014 100644 --- a/main/php_open_temporary_file.h +++ b/main/php_open_temporary_file.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_output.h b/main/php_output.h index 3831478b9f..535b09b46c 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -110,7 +110,7 @@ typedef struct _php_output_context { #define PHP_OUTPUT_TSRMLS(ctx) TSRMLS_FETCH_FROM_CTX((ctx)->tsrm_ls) /* old-style, stateless callback */ -typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC); +typedef void (*php_output_handler_func_t)(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode TSRMLS_DC); /* new-style, opaque context callback */ typedef int (*php_output_handler_context_func_t)(void **handler_context, php_output_context *output_context); /* output handler context dtor */ @@ -123,12 +123,11 @@ typedef struct _php_output_handler *(*php_output_handler_alias_ctor_t)(const cha typedef struct _php_output_handler_user_func_t { zend_fcall_info fci; zend_fcall_info_cache fcc; - zval *zoh; + zval zoh; } php_output_handler_user_func_t; typedef struct _php_output_handler { - char *name; - size_t name_len; + zend_string *name; int flags; int level; size_t size; @@ -144,12 +143,12 @@ typedef struct _php_output_handler { } php_output_handler; ZEND_BEGIN_MODULE_GLOBALS(output) - int flags; zend_stack handlers; php_output_handler *active; php_output_handler *running; const char *output_start_filename; int output_start_lineno; + int flags; ZEND_END_MODULE_GLOBALS(output) PHPAPI ZEND_EXTERN_MODULE_GLOBALS(output); @@ -209,8 +208,8 @@ PHPAPI void php_output_set_implicit_flush(int flush TSRMLS_DC); PHPAPI const char *php_output_get_start_filename(TSRMLS_D); PHPAPI int php_output_get_start_lineno(TSRMLS_D); -PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC); -PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC); +PHPAPI size_t php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC); +PHPAPI size_t php_output_write(const char *str, size_t len TSRMLS_DC); PHPAPI int php_output_flush(TSRMLS_D); PHPAPI void php_output_flush_all(TSRMLS_D); @@ -246,7 +245,7 @@ PHPAPI int php_output_handler_conflict(const char *handler_new, size_t handler_n PHPAPI int php_output_handler_conflict_register(const char *handler_name, size_t handler_name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC); PHPAPI int php_output_handler_reverse_conflict_register(const char *handler_name, size_t handler_name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC); -PHPAPI php_output_handler_alias_ctor_t *php_output_handler_alias(const char *handler_name, size_t handler_name_len TSRMLS_DC); +PHPAPI php_output_handler_alias_ctor_t php_output_handler_alias(const char *handler_name, size_t handler_name_len TSRMLS_DC); PHPAPI int php_output_handler_alias_register(const char *handler_name, size_t handler_name_len, php_output_handler_alias_ctor_t func TSRMLS_DC); END_EXTERN_C() diff --git a/main/php_reentrancy.h b/main/php_reentrancy.h index 2f2e99c0b4..5aac0262a8 100644 --- a/main/php_reentrancy.h +++ b/main/php_reentrancy.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_scandir.c b/main/php_scandir.c index 36c0c648e1..5275f3ddd3 100644 --- a/main/php_scandir.c +++ b/main/php_scandir.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -97,7 +97,7 @@ PHPAPI int php_scandir(const char *dirname, struct dirent **namelist[], int (*se vector = newv; } - dsize = sizeof (struct dirent) + ((strlen(dp->d_name) + 1) * sizeof(char)); + dsize = sizeof (struct dirent) + (((int)strlen(dp->d_name) + 1) * sizeof(char)); newdp = (struct dirent *) malloc(dsize); if (newdp == NULL) { diff --git a/main/php_scandir.h b/main/php_scandir.h index 90708c6872..848f525732 100644 --- a/main/php_scandir.h +++ b/main/php_scandir.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_sprintf.c b/main/php_sprintf.c index e9f956f8dd..f93c16e9aa 100644 --- a/main/php_sprintf.c +++ b/main/php_sprintf.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_stdint.h b/main/php_stdint.h index 14b32d7ca4..4d0d723af6 100644 --- a/main/php_stdint.h +++ b/main/php_stdint.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -28,6 +28,7 @@ # if !defined(_STDINT) # define _STDINT # include "win32/php_stdint.h" +# include "win32/php_inttypes.h" # endif # define HAVE_INT8_T 1 # define HAVE_UINT8_T 1 diff --git a/main/php_streams.h b/main/php_streams.h index d1efa71988..79ceaf2761 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -26,6 +26,8 @@ #endif #include <sys/types.h> #include <sys/stat.h> +#include "zend.h" +#include "zend_stream.h" BEGIN_EXTERN_C() PHPAPI int php_file_le_stream(void); @@ -61,7 +63,7 @@ END_EXTERN_C() * the ultimate ancestor, which is useful, because there can be several layers of calls */ #define php_stream_alloc_rel(ops, thisptr, persistent, mode) _php_stream_alloc((ops), (thisptr), (persistent), (mode) STREAMS_REL_CC TSRMLS_CC) -#define php_stream_copy_to_mem_rel(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC TSRMLS_CC) +#define php_stream_copy_to_mem_rel(src, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC TSRMLS_CC) #define php_stream_fopen_rel(filename, mode, opened, options) _php_stream_fopen((filename), (mode), (opened), (options) STREAMS_REL_CC TSRMLS_CC) @@ -104,7 +106,7 @@ typedef struct _php_stream_filter php_stream_filter; #include "streams/php_stream_filter_api.h" typedef struct _php_stream_statbuf { - struct stat sb; /* regular info */ + zend_stat_t sb; /* regular info */ /* extended info to go here some day: content-type etc. etc. */ } php_stream_statbuf; @@ -123,7 +125,7 @@ typedef struct _php_stream_ops { const char *label; /* label for this ops structure */ /* these are optional */ - int (*seek)(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC); + int (*seek)(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset TSRMLS_DC); int (*cast)(php_stream *stream, int castas, void **ret TSRMLS_DC); int (*stat)(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC); int (*set_option)(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC); @@ -191,37 +193,35 @@ struct _php_stream { php_stream_wrapper *wrapper; /* which wrapper was used to open the stream */ void *wrapperthis; /* convenience pointer for a instance of a wrapper */ - zval *wrapperdata; /* fgetwrapperdata retrieves this */ + zval wrapperdata; /* fgetwrapperdata retrieves this */ int fgetss_state; /* for fgetss to handle multiline tags */ int is_persistent; char mode[16]; /* "rwb" etc. ala stdio */ - int rsrc_id; /* used for auto-cleanup */ + zend_resource *res; /* used for auto-cleanup */ int in_free; /* to prevent recursion during free */ /* so we know how to clean it up correctly. This should be set to * PHP_STREAM_FCLOSE_XXX as appropriate */ int fclose_stdiocast; FILE *stdiocast; /* cache this, otherwise we might leak! */ -#if ZEND_DEBUG int __exposed; /* non-zero if exposed as a zval somewhere */ -#endif char *orig_path; - php_stream_context *context; + zend_resource *ctx; int flags; /* PHP_STREAM_FLAG_XXX */ + int eof; + /* buffer */ - off_t position; /* of underlying stream */ + zend_off_t position; /* of underlying stream */ unsigned char *readbuf; size_t readbuflen; - off_t readpos; - off_t writepos; + zend_off_t readpos; + zend_off_t writepos; /* how much data to read when filling buffer */ size_t chunk_size; - int eof; - #if ZEND_DEBUG const char *open_filename; uint open_lineno; @@ -230,6 +230,9 @@ struct _php_stream { struct _php_stream *enclosing_stream; /* this is a private stream owned by enclosing_stream */ }; /* php_stream */ +#define PHP_STREAM_CONTEXT(stream) \ + ((php_stream_context*) ((stream)->ctx ? ((stream)->ctx->ptr) : NULL)) + /* state definitions when closing down; these are private to streams.c */ #define PHP_STREAM_FCLOSE_NONE 0 #define PHP_STREAM_FCLOSE_FDOPEN 1 @@ -242,21 +245,16 @@ 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) ((php_stream *)(stream))->rsrc_id -#if ZEND_DEBUG +#define php_stream_get_resource_id(stream) ((php_stream *)(stream))->res->handle /* 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++; } +#define php_stream_auto_cleanup(stream) { (stream)->__exposed++; } /* use this to assign the stream to a zval and tell the stream that is * has been exported to the engine; it will expect to be closed automatically * when the resources are auto-destructed */ -# define php_stream_to_zval(stream, zval) { ZVAL_RESOURCE(zval, (stream)->rsrc_id); (stream)->__exposed++; } -#else -# define php_stream_auto_cleanup(stream) /* nothing */ -# define php_stream_to_zval(stream, zval) { ZVAL_RESOURCE(zval, (stream)->rsrc_id); } -#endif +#define php_stream_to_zval(stream, zval) { ZVAL_RES(zval, (stream)->res); (stream)->__exposed++; } -#define php_stream_from_zval(xstr, ppzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream()) -#define php_stream_from_zval_no_verify(xstr, ppzval) (xstr) = (php_stream*)zend_fetch_resource((ppzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream()) +#define php_stream_from_zval(xstr, pzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (pzval), -1, "stream", php_file_le_stream(), php_file_le_pstream()) +#define php_stream_from_zval_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource((pzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream()) BEGIN_EXTERN_C() PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed); @@ -283,11 +281,11 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC); #define php_stream_close(stream) _php_stream_free((stream), PHP_STREAM_FREE_CLOSE TSRMLS_CC) #define php_stream_pclose(stream) _php_stream_free((stream), PHP_STREAM_FREE_CLOSE_PERSISTENT TSRMLS_CC) -PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC); +PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence TSRMLS_DC); #define php_stream_rewind(stream) _php_stream_seek((stream), 0L, SEEK_SET TSRMLS_CC) #define php_stream_seek(stream, offset, whence) _php_stream_seek((stream), (offset), (whence) TSRMLS_CC) -PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC); +PHPAPI zend_off_t _php_stream_tell(php_stream *stream TSRMLS_DC); #define php_stream_tell(stream) _php_stream_tell((stream) TSRMLS_CC) PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC); @@ -322,7 +320,7 @@ 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, const char *delim, size_t delim_len TSRMLS_DC); +PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, 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, const char *buf TSRMLS_DC); @@ -348,11 +346,11 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_ #define php_stream_closedir(dirstream) php_stream_close((dirstream)) #define php_stream_rewinddir(dirstream) php_stream_rewind((dirstream)) -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_dirent_alphasort(const zend_string **a, const zend_string **b); +PHPAPI int php_stream_dirent_alphasortr(const zend_string **a, const zend_string **b); -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); +PHPAPI int _php_stream_scandir(const char *dirname, zend_string **namelist[], int flags, php_stream_context *context, + int (*compare) (const zend_string **a, const zend_string **b) TSRMLS_DC); #define php_stream_scandir(dirname, namelist, context, compare) _php_stream_scandir((dirname), (namelist), 0, (context), (compare) TSRMLS_CC) PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC); @@ -441,9 +439,8 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size /* read all data from stream and put into a buffer. Caller must free buffer * when done. */ -PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, - int persistent STREAMS_DC TSRMLS_DC); -#define php_stream_copy_to_mem(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC) +PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC); +#define php_stream_copy_to_mem(src, maxlen, persistent) _php_stream_copy_to_mem((src), (maxlen), (persistent) STREAMS_CC TSRMLS_CC) /* output all data from a stream */ PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC); @@ -547,7 +544,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_st 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); +PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf 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_syslog.h b/main/php_syslog.h index f8280a8a50..d39fc9b5b2 100644 --- a/main/php_syslog.h +++ b/main/php_syslog.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/php_ticks.c b/main/php_ticks.c index b07f925fab..daa6cde6ff 100644 --- a/main/php_ticks.c +++ b/main/php_ticks.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -46,17 +46,13 @@ static int php_compare_tick_functions(void *elem1, void *elem2) return (func1 == func2); } -PHPAPI void php_add_tick_function(void (*func)(int)) +PHPAPI void php_add_tick_function(void (*func)(int) TSRMLS_DC) { - TSRMLS_FETCH(); - zend_llist_add_element(&PG(tick_functions), (void *)&func); } -PHPAPI void php_remove_tick_function(void (*func)(int)) +PHPAPI void php_remove_tick_function(void (*func)(int) TSRMLS_DC) { - TSRMLS_FETCH(); - zend_llist_del_element(&PG(tick_functions), (void *)func, (int(*)(void*, void*))php_compare_tick_functions); } @@ -69,10 +65,8 @@ static void php_tick_iterator(void *data, void *arg TSRMLS_DC) func(*((int *)arg)); } -void php_run_ticks(int count) +void php_run_ticks(int count TSRMLS_DC) { - TSRMLS_FETCH(); - zend_llist_apply_with_argument(&PG(tick_functions), (llist_apply_with_arg_func_t) php_tick_iterator, &count TSRMLS_CC); } diff --git a/main/php_ticks.h b/main/php_ticks.h index 0f58adac6a..0f8277cc7f 100644 --- a/main/php_ticks.h +++ b/main/php_ticks.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -24,11 +24,11 @@ int php_startup_ticks(TSRMLS_D); void php_deactivate_ticks(TSRMLS_D); void php_shutdown_ticks(TSRMLS_D); -void php_run_ticks(int count); +void php_run_ticks(int count TSRMLS_DC); BEGIN_EXTERN_C() -PHPAPI void php_add_tick_function(void (*func)(int)); -PHPAPI void php_remove_tick_function(void (*func)(int)); +PHPAPI void php_add_tick_function(void (*func)(int) TSRMLS_DC); +PHPAPI void php_remove_tick_function(void (*func)(int) TSRMLS_DC); END_EXTERN_C() #endif diff --git a/main/php_variables.c b/main/php_variables.c index b2df88be61..4f911c2e65 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -23,7 +23,7 @@ #include "php.h" #include "ext/standard/php_standard.h" #include "ext/standard/credits.h" -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include "php_variables.h" #include "php_globals.h" #include "php_content_types.h" @@ -43,16 +43,13 @@ PHPAPI void php_register_variable(char *var, char *strval, zval *track_vars_arra } /* binary-safe version */ -PHPAPI void php_register_variable_safe(char *var, char *strval, int str_len, zval *track_vars_array TSRMLS_DC) +PHPAPI void php_register_variable_safe(char *var, char *strval, size_t str_len, zval *track_vars_array TSRMLS_DC) { zval new_entry; assert(strval != NULL); /* Prepare value */ - Z_STRLEN(new_entry) = str_len; - Z_STRVAL(new_entry) = estrndup(strval, Z_STRLEN(new_entry)); - Z_TYPE(new_entry) = IS_STRING; - + ZVAL_NEW_STR(&new_entry, zend_string_init(strval, str_len, 0)); php_register_variable_ex(var, &new_entry, track_vars_array TSRMLS_CC); } @@ -62,15 +59,15 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars char *ip = NULL; /* index pointer */ char *index; char *var, *var_orig; - int var_len, index_len; - zval *gpc_element, **gpc_element_p; + size_t var_len, index_len; + zval gpc_element, *gpc_element_p; zend_bool is_array = 0; HashTable *symtable1 = NULL; ALLOCA_FLAG(use_heap) assert(var_name != NULL); - if (track_vars_array) { + if (track_vars_array && Z_TYPE_P(track_vars_array) == IS_ARRAY) { symtable1 = Z_ARRVAL_P(track_vars_array); } @@ -113,7 +110,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars } /* GLOBALS hijack attempt, reject parameter */ - if (symtable1 == EG(active_symbol_table) && + if (symtable1 == &EG(symbol_table).ht && var_len == sizeof("GLOBALS")-1 && !memcmp(var, "GLOBALS", sizeof("GLOBALS")-1)) { zval_dtor(val); @@ -128,7 +125,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars int nest_level = 0; while (1) { char *index_s; - int new_idx_len = 0; + size_t new_idx_len = 0; if(++nest_level > PG(max_input_nesting_level)) { HashTable *ht; @@ -136,7 +133,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars if (track_vars_array) { ht = Z_ARRVAL_P(track_vars_array); - zend_symtable_del(ht, var, var_len + 1); + zend_symtable_str_del(ht, var, var_len); } zval_dtor(val); @@ -144,7 +141,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars /* do not output the error message to the screen, this helps us to to avoid "information disclosure" */ if (!PG(display_errors)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variable nesting level exceeded %ld. To increase the limit change max_input_nesting_level in php.ini.", PG(max_input_nesting_level)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variable nesting level exceeded " ZEND_LONG_FMT ". To increase the limit change max_input_nesting_level in php.ini.", PG(max_input_nesting_level)); } free_alloca(var_orig, use_heap); return; @@ -175,23 +172,30 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars } if (!index) { - MAKE_STD_ZVAL(gpc_element); - array_init(gpc_element); - if (zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p) == FAILURE) { + array_init(&gpc_element); + if ((gpc_element_p = zend_hash_next_index_insert(symtable1, &gpc_element)) == NULL) { zval_ptr_dtor(&gpc_element); zval_dtor(val); free_alloca(var_orig, use_heap); return; } } else { - if (zend_symtable_find(symtable1, index, index_len + 1, (void **) &gpc_element_p) == FAILURE - || Z_TYPE_PP(gpc_element_p) != IS_ARRAY) { - MAKE_STD_ZVAL(gpc_element); - array_init(gpc_element); - zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); + gpc_element_p = zend_symtable_str_find(symtable1, index, index_len); + if (!gpc_element_p) { + zval tmp; + array_init(&tmp); + gpc_element_p = zend_symtable_str_update_ind(symtable1, index, index_len, &tmp); + } else { + if (Z_TYPE_P(gpc_element_p) == IS_INDIRECT) { + gpc_element_p = Z_INDIRECT_P(gpc_element_p); + } + if (Z_TYPE_P(gpc_element_p) != IS_ARRAY) { + zval_ptr_dtor(gpc_element_p); + array_init(gpc_element_p); + } } } - symtable1 = Z_ARRVAL_PP(gpc_element_p); + symtable1 = Z_ARRVAL_P(gpc_element_p); /* ip pointed to the '[' character, now obtain the key */ index = index_s; index_len = new_idx_len; @@ -206,11 +210,9 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars } } else { plain_var: - MAKE_STD_ZVAL(gpc_element); - gpc_element->value = val->value; - Z_TYPE_P(gpc_element) = Z_TYPE_P(val); + ZVAL_COPY_VALUE(&gpc_element, val); if (!index) { - if (zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p) == FAILURE) { + if ((gpc_element_p = zend_hash_next_index_insert(symtable1, &gpc_element)) == NULL) { zval_ptr_dtor(&gpc_element); } } else { @@ -220,12 +222,12 @@ plain_var: * to have the same (plain text) cookie name for the same path and we should not overwrite * more specific cookies with the less specific ones. */ - if (PG(http_globals)[TRACK_VARS_COOKIE] && - symtable1 == Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) && - zend_symtable_exists(symtable1, index, index_len + 1)) { + if (Z_TYPE(PG(http_globals)[TRACK_VARS_COOKIE]) != IS_UNDEF && + symtable1 == Z_ARRVAL(PG(http_globals)[TRACK_VARS_COOKIE]) && + zend_symtable_str_exists(symtable1, index, index_len)) { zval_ptr_dtor(&gpc_element); } else { - zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); + gpc_element_p = zend_symtable_str_update_ind(symtable1, index, index_len, &gpc_element); } } } @@ -244,7 +246,7 @@ static zend_bool add_post_var(zval *arr, post_var_data_t *var, zend_bool eof TSR char *ksep, *vsep, *val; size_t klen, vlen; /* FIXME: string-size_t */ - unsigned int new_vlen; + size_t new_vlen; if (var->ptr >= var->end) { return 0; @@ -292,8 +294,8 @@ static inline int add_post_vars(zval *arr, post_var_data_t *vars, zend_bool eof { uint64_t max_vars = PG(max_input_vars); - vars->ptr = vars->str.c; - vars->end = vars->str.c + vars->str.len; + vars->ptr = vars->str.s->val; + vars->end = vars->str.s->val + vars->str.s->len; while (add_post_var(arr, vars, eof TSRMLS_CC)) { if (++vars->cnt > max_vars) { php_error_docref(NULL TSRMLS_CC, E_WARNING, @@ -305,7 +307,7 @@ static inline int add_post_vars(zval *arr, post_var_data_t *vars, zend_bool eof } if (!eof) { - memmove(vars->str.c, vars->ptr, vars->str.len = vars->end - vars->ptr); + memmove(vars->str.s->val, vars->ptr, vars->str.s->len = vars->end - vars->ptr); } return SUCCESS; } @@ -327,9 +329,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler) smart_str_appendl(&post_data.str, buf, len); if (SUCCESS != add_post_vars(arr, &post_data, 0 TSRMLS_CC)) { - if (post_data.str.c) { - efree(post_data.str.c); - } + smart_str_free(&post_data.str); return; } } @@ -339,9 +339,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler) } } - add_post_vars(arr, &post_data, 1 TSRMLS_CC); - if (post_data.str.c) { - efree(post_data.str.c); + if (post_data.str.s) { + add_post_vars(arr, &post_data, 1 TSRMLS_CC); + smart_str_free(&post_data.str); } } } @@ -357,46 +357,39 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data) { char *res = NULL, *var, *val, *separator = NULL; const char *c_var; - zval *array_ptr; + zval array; int free_buffer = 0; char *strtok_buf = NULL; - long count = 0; + zend_long count = 0; + ZVAL_UNDEF(&array); switch (arg) { case PARSE_POST: case PARSE_GET: case PARSE_COOKIE: - ALLOC_ZVAL(array_ptr); - array_init(array_ptr); - INIT_PZVAL(array_ptr); + array_init(&array); switch (arg) { case PARSE_POST: - if (PG(http_globals)[TRACK_VARS_POST]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]); - } - PG(http_globals)[TRACK_VARS_POST] = array_ptr; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]); + ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &array); break; case PARSE_GET: - if (PG(http_globals)[TRACK_VARS_GET]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]); - } - PG(http_globals)[TRACK_VARS_GET] = array_ptr; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]); + ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_GET], &array); break; case PARSE_COOKIE: - if (PG(http_globals)[TRACK_VARS_COOKIE]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]); - } - PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]); + ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_COOKIE], &array); break; } break; default: - array_ptr = destArray; + ZVAL_COPY_VALUE(&array, destArray); break; } if (arg == PARSE_POST) { - sapi_handle_post(array_ptr TSRMLS_CC); + sapi_handle_post(&array TSRMLS_CC); return; } @@ -451,31 +444,31 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data) } 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)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded " ZEND_LONG_FMT ". To increase the limit change max_input_vars in php.ini.", PG(max_input_vars)); break; } if (val) { /* have a value */ - int val_len; - unsigned int new_val_len; + size_t val_len; + size_t new_val_len; *val++ = '\0'; php_url_decode(var, strlen(var)); val_len = php_url_decode(val, strlen(val)); val = estrndup(val, val_len); if (sapi_module.input_filter(arg, var, &val, val_len, &new_val_len TSRMLS_CC)) { - php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC); + php_register_variable_safe(var, val, new_val_len, &array TSRMLS_CC); } efree(val); } else { - int val_len; - unsigned int new_val_len; + size_t val_len; + size_t new_val_len; php_url_decode(var, strlen(var)); val_len = 0; val = estrndup("", val_len); if (sapi_module.input_filter(arg, var, &val, val_len, &new_val_len TSRMLS_CC)) { - php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC); + php_register_variable_safe(var, val, new_val_len, &array TSRMLS_CC); } efree(val); } @@ -528,7 +521,7 @@ zend_bool php_std_auto_global_callback(char *name, uint name_len TSRMLS_DC) */ static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC) { - zval *arr, *argc, *tmp; + zval arr, argc, tmp; int count = 0; char *ss, *space; @@ -536,22 +529,15 @@ static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC) return; } - ALLOC_INIT_ZVAL(arr); - array_init(arr); + array_init(&arr); /* Prepare argv */ if (SG(request_info).argc) { /* are we in cli sapi? */ int i; for (i = 0; i < SG(request_info).argc; i++) { - ALLOC_ZVAL(tmp); - Z_TYPE_P(tmp) = IS_STRING; - Z_STRLEN_P(tmp) = strlen(SG(request_info).argv[i]); - Z_STRVAL_P(tmp) = estrndup(SG(request_info).argv[i], Z_STRLEN_P(tmp)); - INIT_PZVAL(tmp); - if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(zval *), NULL) == FAILURE) { - if (Z_TYPE_P(tmp) == IS_STRING) { - efree(Z_STRVAL_P(tmp)); - } + ZVAL_STRING(&tmp, SG(request_info).argv[i]); + if (zend_hash_next_index_insert(Z_ARRVAL(arr), &tmp) == NULL) { + zend_string_free(Z_STR(tmp)); } } } else if (s && *s) { @@ -562,16 +548,10 @@ static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC) *space = '\0'; } /* auto-type */ - ALLOC_ZVAL(tmp); - Z_TYPE_P(tmp) = IS_STRING; - Z_STRLEN_P(tmp) = strlen(ss); - Z_STRVAL_P(tmp) = estrndup(ss, Z_STRLEN_P(tmp)); - INIT_PZVAL(tmp); + ZVAL_STRING(&tmp, ss); count++; - if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(zval *), NULL) == FAILURE) { - if (Z_TYPE_P(tmp) == IS_STRING) { - efree(Z_STRVAL_P(tmp)); - } + if (zend_hash_next_index_insert(Z_ARRVAL(arr), &tmp) == NULL) { + zend_string_free(Z_STR(tmp)); } if (space) { *space = '+'; @@ -583,28 +563,23 @@ static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC) } /* prepare argc */ - ALLOC_INIT_ZVAL(argc); if (SG(request_info).argc) { - Z_LVAL_P(argc) = SG(request_info).argc; + ZVAL_LONG(&argc, SG(request_info).argc); } else { - Z_LVAL_P(argc) = count; + ZVAL_LONG(&argc, count); } - Z_TYPE_P(argc) = IS_LONG; if (SG(request_info).argc) { - Z_ADDREF_P(arr); - Z_ADDREF_P(argc); - zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL); - zend_hash_update(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL); + Z_ADDREF(arr); + zend_hash_str_update(&EG(symbol_table).ht, "argv", sizeof("argv")-1, &arr); + zend_hash_str_add(&EG(symbol_table).ht, "argc", sizeof("argc")-1, &argc); } - if (track_vars_array) { - Z_ADDREF_P(arr); - Z_ADDREF_P(argc); - zend_hash_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL); - zend_hash_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL); + if (track_vars_array && Z_TYPE_P(track_vars_array) == IS_ARRAY) { + Z_ADDREF(arr); + zend_hash_str_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv")-1, &arr); + zend_hash_str_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc")-1, &argc); } zval_ptr_dtor(&arr); - zval_ptr_dtor(&argc); } /* }}} */ @@ -612,40 +587,31 @@ static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC) */ static inline void php_register_server_variables(TSRMLS_D) { - zval *array_ptr = NULL; - - ALLOC_ZVAL(array_ptr); - array_init(array_ptr); - INIT_PZVAL(array_ptr); - if (PG(http_globals)[TRACK_VARS_SERVER]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]); - } - PG(http_globals)[TRACK_VARS_SERVER] = array_ptr; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]); + array_init(&PG(http_globals)[TRACK_VARS_SERVER]); /* Server variables */ if (sapi_module.register_server_variables) { - sapi_module.register_server_variables(array_ptr TSRMLS_CC); + sapi_module.register_server_variables(&PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); } /* PHP Authentication support */ if (SG(request_info).auth_user) { - php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, array_ptr TSRMLS_CC); + php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, &PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); } if (SG(request_info).auth_password) { - php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, array_ptr TSRMLS_CC); + php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, &PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); } if (SG(request_info).auth_digest) { - php_register_variable("PHP_AUTH_DIGEST", SG(request_info).auth_digest, array_ptr TSRMLS_CC); + php_register_variable("PHP_AUTH_DIGEST", SG(request_info).auth_digest, &PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); } /* store request init time */ { zval request_time_float, request_time_long; - Z_TYPE(request_time_float) = IS_DOUBLE; - Z_DVAL(request_time_float) = sapi_get_request_time(TSRMLS_C); - php_register_variable_ex("REQUEST_TIME_FLOAT", &request_time_float, array_ptr TSRMLS_CC); - Z_TYPE(request_time_long) = IS_LONG; - Z_LVAL(request_time_long) = zend_dval_to_lval(Z_DVAL(request_time_float)); - php_register_variable_ex("REQUEST_TIME", &request_time_long, array_ptr TSRMLS_CC); + ZVAL_DOUBLE(&request_time_float, sapi_get_request_time(TSRMLS_C)); + php_register_variable_ex("REQUEST_TIME_FLOAT", &request_time_float, &PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); + ZVAL_LONG(&request_time_long, zend_dval_to_lval(Z_DVAL(request_time_float))); + php_register_variable_ex("REQUEST_TIME", &request_time_long, &PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); } } @@ -655,45 +621,37 @@ static inline void php_register_server_variables(TSRMLS_D) */ static void php_autoglobal_merge(HashTable *dest, HashTable *src TSRMLS_DC) { - zval **src_entry, **dest_entry; - char *string_key; - uint string_key_len; - ulong num_key; - HashPosition pos; - int key_type; - int globals_check = (dest == (&EG(symbol_table))); - - zend_hash_internal_pointer_reset_ex(src, &pos); - while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) { - key_type = zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos); - if (Z_TYPE_PP(src_entry) != IS_ARRAY - || (key_type == HASH_KEY_IS_STRING && zend_hash_find(dest, string_key, string_key_len, (void **) &dest_entry) != SUCCESS) - || (key_type == HASH_KEY_IS_LONG && zend_hash_index_find(dest, num_key, (void **)&dest_entry) != SUCCESS) - || Z_TYPE_PP(dest_entry) != IS_ARRAY - ) { - Z_ADDREF_PP(src_entry); - if (key_type == HASH_KEY_IS_STRING) { - if (!globals_check || string_key_len != sizeof("GLOBALS") || memcmp(string_key, "GLOBALS", sizeof("GLOBALS") - 1)) { - zend_hash_update(dest, string_key, string_key_len, src_entry, sizeof(zval *), NULL); - } else { - Z_DELREF_PP(src_entry); + zval *src_entry, *dest_entry; + zend_string *string_key; + zend_ulong num_key; + int globals_check = (dest == (&EG(symbol_table).ht)); + + ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { + if (Z_TYPE_P(src_entry) != IS_ARRAY + || (string_key && (dest_entry = zend_hash_find(dest, string_key)) == NULL) + || (string_key == NULL && (dest_entry = zend_hash_index_find(dest, num_key)) == NULL) + || Z_TYPE_P(dest_entry) != IS_ARRAY) { + if (Z_REFCOUNTED_P(src_entry)) { + Z_ADDREF_P(src_entry); + } + if (string_key) { + if (!globals_check || string_key->len != sizeof("GLOBALS") - 1 + || memcmp(string_key->val, "GLOBALS", sizeof("GLOBALS") - 1)) { + zend_hash_update(dest, string_key, src_entry); + } else if (Z_REFCOUNTED_P(src_entry)) { + Z_DELREF_P(src_entry); } } else { - zend_hash_index_update(dest, num_key, src_entry, sizeof(zval *), NULL); + zend_hash_index_update(dest, num_key, src_entry); } } else { SEPARATE_ZVAL(dest_entry); - php_autoglobal_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC); + php_autoglobal_merge(Z_ARRVAL_P(dest_entry), Z_ARRVAL_P(src_entry) TSRMLS_CC); } - zend_hash_move_forward_ex(src, &pos); - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ -static zend_bool php_auto_globals_create_server(const char *name, uint name_len TSRMLS_DC); -static zend_bool php_auto_globals_create_env(const char *name, uint name_len TSRMLS_DC); -static zend_bool php_auto_globals_create_request(const char *name, uint name_len TSRMLS_DC); - /* {{{ php_hash_environment */ PHPAPI int php_hash_environment(TSRMLS_D) @@ -701,171 +659,126 @@ PHPAPI int php_hash_environment(TSRMLS_D) memset(PG(http_globals), 0, sizeof(PG(http_globals))); zend_activate_auto_globals(TSRMLS_C); if (PG(register_argc_argv)) { - php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); + php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); } return SUCCESS; } /* }}} */ -static zend_bool php_auto_globals_create_get(const char *name, uint name_len TSRMLS_DC) +static zend_bool php_auto_globals_create_get(zend_string *name TSRMLS_DC) { - zval *vars; - if (PG(variables_order) && (strchr(PG(variables_order),'G') || strchr(PG(variables_order),'g'))) { sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); - vars = PG(http_globals)[TRACK_VARS_GET]; } else { - ALLOC_ZVAL(vars); - array_init(vars); - INIT_PZVAL(vars); - if (PG(http_globals)[TRACK_VARS_GET]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]); - } - PG(http_globals)[TRACK_VARS_GET] = vars; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]); + array_init(&PG(http_globals)[TRACK_VARS_GET]); } - zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL); - Z_ADDREF_P(vars); + zend_hash_update(&EG(symbol_table).ht, name, &PG(http_globals)[TRACK_VARS_GET]); + Z_ADDREF(PG(http_globals)[TRACK_VARS_GET]); return 0; /* don't rearm */ } -static zend_bool php_auto_globals_create_post(const char *name, uint name_len TSRMLS_DC) +static zend_bool php_auto_globals_create_post(zend_string *name TSRMLS_DC) { - zval *vars; - if (PG(variables_order) && (strchr(PG(variables_order),'P') || strchr(PG(variables_order),'p')) && + !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) { sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); - vars = PG(http_globals)[TRACK_VARS_POST]; } else { - ALLOC_ZVAL(vars); - array_init(vars); - INIT_PZVAL(vars); - if (PG(http_globals)[TRACK_VARS_POST]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]); - } - PG(http_globals)[TRACK_VARS_POST] = vars; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]); + array_init(&PG(http_globals)[TRACK_VARS_POST]); } - zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL); - Z_ADDREF_P(vars); + zend_hash_update(&EG(symbol_table).ht, name, &PG(http_globals)[TRACK_VARS_POST]); + Z_ADDREF(PG(http_globals)[TRACK_VARS_POST]); return 0; /* don't rearm */ } -static zend_bool php_auto_globals_create_cookie(const char *name, uint name_len TSRMLS_DC) +static zend_bool php_auto_globals_create_cookie(zend_string *name TSRMLS_DC) { - zval *vars; - if (PG(variables_order) && (strchr(PG(variables_order),'C') || strchr(PG(variables_order),'c'))) { sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); - vars = PG(http_globals)[TRACK_VARS_COOKIE]; } else { - ALLOC_ZVAL(vars); - array_init(vars); - INIT_PZVAL(vars); - if (PG(http_globals)[TRACK_VARS_COOKIE]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]); - } - PG(http_globals)[TRACK_VARS_COOKIE] = vars; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]); + array_init(&PG(http_globals)[TRACK_VARS_COOKIE]); } - zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL); - Z_ADDREF_P(vars); + zend_hash_update(&EG(symbol_table).ht, name, &PG(http_globals)[TRACK_VARS_COOKIE]); + Z_ADDREF(PG(http_globals)[TRACK_VARS_COOKIE]); return 0; /* don't rearm */ } -static zend_bool php_auto_globals_create_files(const char *name, uint name_len TSRMLS_DC) +static zend_bool php_auto_globals_create_files(zend_string *name TSRMLS_DC) { - zval *vars; - - if (PG(http_globals)[TRACK_VARS_FILES]) { - vars = PG(http_globals)[TRACK_VARS_FILES]; - } else { - ALLOC_ZVAL(vars); - array_init(vars); - INIT_PZVAL(vars); - PG(http_globals)[TRACK_VARS_FILES] = vars; + if (Z_TYPE(PG(http_globals)[TRACK_VARS_FILES]) == IS_UNDEF) { + array_init(&PG(http_globals)[TRACK_VARS_FILES]); } - zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL); - Z_ADDREF_P(vars); + zend_hash_update(&EG(symbol_table).ht, name, &PG(http_globals)[TRACK_VARS_FILES]); + Z_ADDREF(PG(http_globals)[TRACK_VARS_FILES]); return 0; /* don't rearm */ } -static zend_bool php_auto_globals_create_server(const char *name, uint name_len TSRMLS_DC) +static zend_bool php_auto_globals_create_server(zend_string *name TSRMLS_DC) { if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) { php_register_server_variables(TSRMLS_C); if (PG(register_argc_argv)) { if (SG(request_info).argc) { - zval **argc, **argv; + zval *argc, *argv; - if (zend_hash_find(&EG(symbol_table), "argc", sizeof("argc"), (void**)&argc) == SUCCESS && - zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void**)&argv) == SUCCESS) { - Z_ADDREF_PP(argc); - Z_ADDREF_PP(argv); - zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), argv, sizeof(zval *), NULL); - zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc"), argc, sizeof(zval *), NULL); + if ((argc = zend_hash_str_find(&EG(symbol_table).ht, "argc", sizeof("argc")-1)) != NULL && + (argv = zend_hash_str_find(&EG(symbol_table).ht, "argv", sizeof("argv")-1)) != NULL) { + Z_ADDREF_P(argv); + zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv")-1, argv); + zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc")-1, argc); } } else { - php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); + php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); } } } else { - zval *server_vars=NULL; - ALLOC_ZVAL(server_vars); - array_init(server_vars); - INIT_PZVAL(server_vars); - if (PG(http_globals)[TRACK_VARS_SERVER]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]); - } - PG(http_globals)[TRACK_VARS_SERVER] = server_vars; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]); + array_init(&PG(http_globals)[TRACK_VARS_SERVER]); } - zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL); - Z_ADDREF_P(PG(http_globals)[TRACK_VARS_SERVER]); + zend_hash_update(&EG(symbol_table).ht, name, &PG(http_globals)[TRACK_VARS_SERVER]); + Z_ADDREF(PG(http_globals)[TRACK_VARS_SERVER]); return 0; /* don't rearm */ } -static zend_bool php_auto_globals_create_env(const char *name, uint name_len TSRMLS_DC) +static zend_bool php_auto_globals_create_env(zend_string *name TSRMLS_DC) { - zval *env_vars = NULL; - ALLOC_ZVAL(env_vars); - array_init(env_vars); - INIT_PZVAL(env_vars); - if (PG(http_globals)[TRACK_VARS_ENV]) { - zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_ENV]); - } - PG(http_globals)[TRACK_VARS_ENV] = env_vars; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_ENV]); + array_init(&PG(http_globals)[TRACK_VARS_ENV]); if (PG(variables_order) && (strchr(PG(variables_order),'E') || strchr(PG(variables_order),'e'))) { - php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC); + php_import_environment_variables(&PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC); } - zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL); - Z_ADDREF_P(PG(http_globals)[TRACK_VARS_ENV]); + zend_hash_update(&EG(symbol_table).ht, name, &PG(http_globals)[TRACK_VARS_ENV]); + Z_ADDREF(PG(http_globals)[TRACK_VARS_ENV]); return 0; /* don't rearm */ } -static zend_bool php_auto_globals_create_request(const char *name, uint name_len TSRMLS_DC) +static zend_bool php_auto_globals_create_request(zend_string *name TSRMLS_DC) { - zval *form_variables; + zval form_variables; unsigned char _gpc_flags[3] = {0, 0, 0}; char *p; - ALLOC_ZVAL(form_variables); - array_init(form_variables); - INIT_PZVAL(form_variables); + array_init(&form_variables); if (PG(request_order) != NULL) { p = PG(request_order); @@ -878,40 +791,40 @@ static zend_bool php_auto_globals_create_request(const char *name, uint name_len case 'g': case 'G': if (!_gpc_flags[0]) { - php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]) TSRMLS_CC); + php_autoglobal_merge(Z_ARRVAL(form_variables), Z_ARRVAL(PG(http_globals)[TRACK_VARS_GET]) TSRMLS_CC); _gpc_flags[0] = 1; } break; case 'p': case 'P': if (!_gpc_flags[1]) { - php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]) TSRMLS_CC); + php_autoglobal_merge(Z_ARRVAL(form_variables), Z_ARRVAL(PG(http_globals)[TRACK_VARS_POST]) TSRMLS_CC); _gpc_flags[1] = 1; } break; case 'c': case 'C': if (!_gpc_flags[2]) { - php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) TSRMLS_CC); + php_autoglobal_merge(Z_ARRVAL(form_variables), Z_ARRVAL(PG(http_globals)[TRACK_VARS_COOKIE]) TSRMLS_CC); _gpc_flags[2] = 1; } break; } } - zend_hash_update(&EG(symbol_table), name, name_len + 1, &form_variables, sizeof(zval *), NULL); + zend_hash_update(&EG(symbol_table).ht, name, &form_variables); return 0; } void php_startup_auto_globals(TSRMLS_D) { - zend_register_auto_global(ZEND_STRL("_GET"), 0, php_auto_globals_create_get TSRMLS_CC); - zend_register_auto_global(ZEND_STRL("_POST"), 0, php_auto_globals_create_post TSRMLS_CC); - zend_register_auto_global(ZEND_STRL("_COOKIE"), 0, php_auto_globals_create_cookie TSRMLS_CC); - zend_register_auto_global(ZEND_STRL("_SERVER"), PG(auto_globals_jit), php_auto_globals_create_server TSRMLS_CC); - zend_register_auto_global(ZEND_STRL("_ENV"), PG(auto_globals_jit), php_auto_globals_create_env TSRMLS_CC); - zend_register_auto_global(ZEND_STRL("_REQUEST"), PG(auto_globals_jit), php_auto_globals_create_request TSRMLS_CC); - zend_register_auto_global(ZEND_STRL("_FILES"), 0, php_auto_globals_create_files TSRMLS_CC); + zend_register_auto_global(zend_string_init("_GET", sizeof("_GET")-1, 1), 0, php_auto_globals_create_get TSRMLS_CC); + zend_register_auto_global(zend_string_init("_POST", sizeof("_POST")-1, 1), 0, php_auto_globals_create_post TSRMLS_CC); + zend_register_auto_global(zend_string_init("_COOKIE", sizeof("_COOKIE")-1, 1), 0, php_auto_globals_create_cookie TSRMLS_CC); + zend_register_auto_global(zend_string_init("_SERVER", sizeof("_SERVER")-1, 1), PG(auto_globals_jit), php_auto_globals_create_server TSRMLS_CC); + zend_register_auto_global(zend_string_init("_ENV", sizeof("_ENV")-1, 1), PG(auto_globals_jit), php_auto_globals_create_env TSRMLS_CC); + zend_register_auto_global(zend_string_init("_REQUEST", sizeof("_REQUEST")-1, 1), PG(auto_globals_jit), php_auto_globals_create_request TSRMLS_CC); + zend_register_auto_global(zend_string_init("_FILES", sizeof("_FILES")-1, 1), 0, php_auto_globals_create_files TSRMLS_CC); } /* diff --git a/main/php_variables.h b/main/php_variables.h index 2331c582e6..08abeb5267 100644 --- a/main/php_variables.h +++ b/main/php_variables.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -38,7 +38,7 @@ void php_startup_auto_globals(TSRMLS_D); extern PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC); PHPAPI void php_register_variable(char *var, char *val, zval *track_vars_array TSRMLS_DC); /* binary-safe version */ -PHPAPI void php_register_variable_safe(char *var, char *val, int val_len, zval *track_vars_array TSRMLS_DC); +PHPAPI void php_register_variable_safe(char *var, char *val, size_t val_len, zval *track_vars_array TSRMLS_DC); PHPAPI void php_register_variable_ex(char *var, zval *val, zval *track_vars_array TSRMLS_DC); PHPAPI int php_hash_environment(TSRMLS_D); diff --git a/main/php_version.h b/main/php_version.h index 83b9cc2f27..d48ab24141 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 6 -#define PHP_RELEASE_VERSION 5 +#define PHP_MAJOR_VERSION 7 +#define PHP_MINOR_VERSION 0 +#define PHP_RELEASE_VERSION 0 #define PHP_EXTRA_VERSION "-dev" -#define PHP_VERSION "5.6.5-dev" -#define PHP_VERSION_ID 50605 +#define PHP_VERSION "7.0.0-dev" +#define PHP_VERSION_ID 70000 diff --git a/main/reentrancy.c b/main/reentrancy.c index dd411f478b..4aca23eb1a 100644 --- a/main/reentrancy.c +++ b/main/reentrancy.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/rfc1867.c b/main/rfc1867.c index 806a292872..e8b15f8494 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -58,7 +58,7 @@ static php_rfc1867_basename_t php_rfc1867_basename = NULL; PHPAPI int (*php_rfc1867_callback)(unsigned int event, void *event_data, void **extra TSRMLS_DC) = NULL; -static void safe_php_register_variable(char *var, char *strval, int val_len, zval *track_vars_array, zend_bool override_protection TSRMLS_DC); +static void safe_php_register_variable(char *var, char *strval, size_t val_len, zval *track_vars_array, zend_bool override_protection TSRMLS_DC); /* The longest property name we use in an uploaded file array */ #define MAX_SIZE_OF_INDEX sizeof("[tmp_name]") @@ -149,21 +149,19 @@ static void normalize_protected_variable(char *varname TSRMLS_DC) /* {{{ */ static void add_protected_variable(char *varname TSRMLS_DC) /* {{{ */ { - int dummy = 1; - normalize_protected_variable(varname TSRMLS_CC); - zend_hash_add(&PG(rfc1867_protected_variables), varname, strlen(varname)+1, &dummy, sizeof(int), NULL); + zend_hash_str_add_empty_element(&PG(rfc1867_protected_variables), varname, strlen(varname)); } /* }}} */ static zend_bool is_protected_variable(char *varname TSRMLS_DC) /* {{{ */ { normalize_protected_variable(varname TSRMLS_CC); - return zend_hash_exists(&PG(rfc1867_protected_variables), varname, strlen(varname)+1); + return zend_hash_str_exists(&PG(rfc1867_protected_variables), varname, strlen(varname)); } /* }}} */ -static void safe_php_register_variable(char *var, char *strval, int val_len, zval *track_vars_array, zend_bool override_protection TSRMLS_DC) /* {{{ */ +static void safe_php_register_variable(char *var, char *strval, size_t val_len, zval *track_vars_array, zend_bool override_protection TSRMLS_DC) /* {{{ */ { if (override_protection || !is_protected_variable(var TSRMLS_CC)) { php_register_variable_safe(var, strval, val_len, track_vars_array TSRMLS_CC); @@ -191,16 +189,23 @@ static void register_http_post_files_variable_ex(char *var, zval *val, zval *htt } /* }}} */ -static int unlink_filename(char **filename TSRMLS_DC) /* {{{ */ +static int unlink_filename(zval *el TSRMLS_DC) /* {{{ */ { - VCWD_UNLINK(*filename); + char *filename = (char*)Z_PTR_P(el); + VCWD_UNLINK(filename); return 0; } /* }}} */ + +static void free_filename(zval *el) { + char *filename = (char*)Z_PTR_P(el); + efree(filename); +} + void destroy_uploaded_files_hash(TSRMLS_D) /* {{{ */ { - zend_hash_apply(SG(rfc1867_uploaded_files), (apply_func_t) unlink_filename TSRMLS_CC); + zend_hash_apply(SG(rfc1867_uploaded_files), unlink_filename TSRMLS_CC); zend_hash_destroy(SG(rfc1867_uploaded_files)); FREE_HASHTABLE(SG(rfc1867_uploaded_files)); } @@ -256,7 +261,7 @@ static int fill_buffer(multipart_buffer *self TSRMLS_DC) char *buf = self->buffer + self->bytes_in_buffer; - actual_read = sapi_module.read_post(buf, bytes_to_read TSRMLS_CC); + actual_read = (int)sapi_module.read_post(buf, bytes_to_read TSRMLS_CC); /* update the buffer length */ if (actual_read > 0) { @@ -295,7 +300,7 @@ static multipart_buffer *multipart_buffer_new(char *boundary, int boundary_len T spprintf(&self->boundary, 0, "--%s", boundary); - self->boundary_next_len = spprintf(&self->boundary_next, 0, "\n--%s", boundary); + self->boundary_next_len = (int)spprintf(&self->boundary_next, 0, "\n--%s", boundary); self->buf_begin = self->buffer; self->bytes_in_buffer = 0; @@ -437,8 +442,8 @@ static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header T } else if (zend_llist_count(header)) { /* If no ':' on the line, add to previous line */ - prev_len = strlen(prev_entry.value); - cur_len = strlen(line); + prev_len = (int)strlen(prev_entry.value); + cur_len = (int)strlen(line); entry.value = emalloc(prev_len + cur_len + 1); memcpy(entry.value, prev_entry.value, prev_len); @@ -546,7 +551,7 @@ static char *php_ap_getword_conf(const zend_encoding *encoding, char *str TSRMLS char quote = *str; str++; - return substring_conf(str, strlen(str), quote); + return substring_conf(str, (int)strlen(str), quote); } else { char *strend = str; @@ -606,9 +611,9 @@ static void *php_ap_memstr(char *haystack, int haystacklen, char *needle, int ne } /* read until a boundary condition */ -static int multipart_buffer_read(multipart_buffer *self, char *buf, int bytes, int *end TSRMLS_DC) +static int multipart_buffer_read(multipart_buffer *self, char *buf, size_t bytes, int *end TSRMLS_DC) { - int len, max; + size_t len, max; char *bound; /* fill buffer if needed */ @@ -641,18 +646,18 @@ static int multipart_buffer_read(multipart_buffer *self, char *buf, int bytes, i } /* update the buffer */ - self->bytes_in_buffer -= len; + self->bytes_in_buffer -= (int)len; self->buf_begin += len; } - return len; + return (int)len; } /* XXX: this is horrible memory-usage-wise, but we only expect to do this on small pieces of form data. */ -static char *multipart_buffer_read_body(multipart_buffer *self, unsigned int *len TSRMLS_DC) +static char *multipart_buffer_read_body(multipart_buffer *self, size_t *len TSRMLS_DC) { char buf[FILLUNIT], *out=NULL; int total_bytes=0, read_bytes=0; @@ -684,7 +689,6 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ 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; zval *array_ptr = (zval *) arg; @@ -697,7 +701,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ php_rfc1867_getword_t getword; php_rfc1867_getword_conf_t getword_conf; php_rfc1867_basename_t _basename; - long count = 0; + zend_long count = 0; if (php_rfc1867_encoding_translation(TSRMLS_C) && internal_encoding) { getword = php_rfc1867_getword; @@ -710,14 +714,14 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } if (SG(post_max_size) > 0 && SG(request_info).content_length > SG(post_max_size)) { - sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size)); + sapi_module.sapi_error(E_WARNING, "POST Content-Length of " ZEND_LONG_FMT " bytes exceeds the limit of " ZEND_LONG_FMT " bytes", SG(request_info).content_length, SG(post_max_size)); return; } /* Get the boundary */ boundary = strstr(content_type_dup, "boundary"); if (!boundary) { - int content_type_len = strlen(content_type_dup); + int content_type_len = (int)strlen(content_type_dup); char *content_type_lcase = estrndup(content_type_dup, content_type_len); php_strtolower(content_type_lcase, content_type_len); @@ -734,7 +738,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } boundary++; - boundary_len = strlen(boundary); + boundary_len = (int)strlen(boundary); if (boundary[0] == '"') { boundary++; @@ -759,16 +763,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } /* Initialize $_FILES[] */ - zend_hash_init(&PG(rfc1867_protected_variables), 5, NULL, NULL, 0); + zend_hash_init(&PG(rfc1867_protected_variables), 8, NULL, NULL, 0); ALLOC_HASHTABLE(uploaded_files); - zend_hash_init(uploaded_files, 5, NULL, (dtor_func_t) free_estring, 0); + zend_hash_init(uploaded_files, 8, NULL, free_filename, 0); SG(rfc1867_uploaded_files) = uploaded_files; - ALLOC_ZVAL(http_post_files); - array_init(http_post_files); - INIT_PZVAL(http_post_files); - PG(http_globals)[TRACK_VARS_FILES] = http_post_files; + array_init(&PG(http_globals)[TRACK_VARS_FILES]); zend_llist_init(&header, sizeof(mime_header_entry), (llist_dtor_func_t) php_free_hdr_entry, 0); @@ -786,7 +787,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ char buff[FILLUNIT]; char *cd = NULL, *param = NULL, *filename = NULL, *tmp = NULL; size_t blen = 0, wlen = 0; - off_t offset; + zend_off_t offset; zend_llist_clean(&header); @@ -849,9 +850,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ /* Normal form variable, safe to read all data into memory */ if (!filename && param) { - unsigned int value_len; + size_t value_len; char *value = multipart_buffer_read_body(mbuff, &value_len TSRMLS_CC); - unsigned int new_val_len; /* Dummy variable */ + size_t new_val_len; /* Dummy variable */ if (!value) { value = estrdup(""); @@ -888,7 +889,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ safe_php_register_variable(param, value, new_val_len, array_ptr, 0 TSRMLS_CC); } else { if (count == PG(max_input_vars) + 1) { - 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)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded " ZEND_LONG_FMT ". To increase the limit change max_input_vars in php.ini.", PG(max_input_vars)); } if (php_rfc1867_callback != NULL) { @@ -1033,18 +1034,22 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } } - if (PG(upload_max_filesize) > 0 && (long)(total_bytes+blen) > PG(upload_max_filesize)) { + if (PG(upload_max_filesize) > 0 && (zend_long)(total_bytes+blen) > PG(upload_max_filesize)) { #if DEBUG_FILE_UPLOAD - sapi_module.sapi_error(E_NOTICE, "upload_max_filesize of %ld bytes exceeded - file [%s=%s] not saved", PG(upload_max_filesize), param, filename); + sapi_module.sapi_error(E_NOTICE, "upload_max_filesize of " ZEND_LONG_FMT " bytes exceeded - file [%s=%s] not saved", PG(upload_max_filesize), param, filename); #endif cancel_upload = UPLOAD_ERROR_A; - } else if (max_file_size && ((long)(total_bytes+blen) > max_file_size)) { + } else if (max_file_size && ((zend_long)(total_bytes+blen) > max_file_size)) { #if DEBUG_FILE_UPLOAD - sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of %ld bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename); + sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of " ZEND_LONG_FMT " bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename); #endif cancel_upload = UPLOAD_ERROR_B; } else if (blen > 0) { +#ifdef PHP_WIN32 + wlen = write(fd, buff, (unsigned int)blen); +#else wlen = write(fd, buff, blen); +#endif if (wlen == -1) { /* write failed */ @@ -1103,7 +1108,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } temp_filename = ""; } else { - zend_hash_add(SG(rfc1867_uploaded_files), temp_filename, strlen(temp_filename) + 1, &temp_filename, sizeof(char *), NULL); + zend_hash_str_add_ptr(SG(rfc1867_uploaded_files), temp_filename, strlen(temp_filename), temp_filename); } /* is_arr_upload is true when name of file upload field @@ -1112,7 +1117,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ is_arr_upload = (start_arr = strchr(param,'[')) && (param[strlen(param)-1] == ']'); if (is_arr_upload) { - array_len = strlen(start_arr); + array_len = (int)strlen(start_arr); if (array_index) { efree(array_index); } @@ -1121,7 +1126,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ /* Add $foo_name */ if (llen < strlen(param) + MAX_SIZE_OF_INDEX + 1) { - llen = strlen(param); + llen = (int)strlen(param); lbuf = (char *) safe_erealloc(lbuf, llen, 1, MAX_SIZE_OF_INDEX + 1); llen += MAX_SIZE_OF_INDEX + 1; } @@ -1154,7 +1159,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } else { snprintf(lbuf, llen, "%s[name]", param); } - register_http_post_files_variable(lbuf, s, http_post_files, 0 TSRMLS_CC); + register_http_post_files_variable(lbuf, s, &PG(http_globals)[TRACK_VARS_FILES], 0 TSRMLS_CC); efree(filename); s = NULL; @@ -1185,7 +1190,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } else { snprintf(lbuf, llen, "%s[type]", param); } - register_http_post_files_variable(lbuf, cd, http_post_files, 0 TSRMLS_CC); + register_http_post_files_variable(lbuf, cd, &PG(http_globals)[TRACK_VARS_FILES], 0 TSRMLS_CC); /* Restore Content-Type Header */ if (s != NULL) { @@ -1203,7 +1208,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ /* if param is of form xxx[.*] this will cut it to xxx */ if (!is_anonymous) { - ZVAL_STRING(&zfilename, temp_filename, 1); + ZVAL_STRING(&zfilename, temp_filename); safe_php_register_variable_ex(param, &zfilename, NULL, 1 TSRMLS_CC); } @@ -1214,8 +1219,8 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ snprintf(lbuf, llen, "%s[tmp_name]", param); } add_protected_variable(lbuf TSRMLS_CC); - ZVAL_STRING(&zfilename, temp_filename, 1); - register_http_post_files_variable_ex(lbuf, &zfilename, http_post_files, 1 TSRMLS_CC); + ZVAL_STRING(&zfilename, temp_filename); + register_http_post_files_variable_ex(lbuf, &zfilename, &PG(http_globals)[TRACK_VARS_FILES], 1 TSRMLS_CC); } { @@ -1229,7 +1234,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ if (cancel_upload) { ZVAL_LONG(&file_size, 0); } else { - if (total_bytes > LONG_MAX) { + if (total_bytes > ZEND_LONG_MAX) { #ifdef PHP_WIN32 if (_i64toa_s(total_bytes, file_size_buf, 65, 10)) { file_size_buf[0] = '0'; @@ -1253,7 +1258,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } else { snprintf(lbuf, llen, "%s[error]", param); } - register_http_post_files_variable_ex(lbuf, &error_type, http_post_files, 0 TSRMLS_CC); + register_http_post_files_variable_ex(lbuf, &error_type, &PG(http_globals)[TRACK_VARS_FILES], 0 TSRMLS_CC); /* Add $foo_size */ if (is_arr_upload) { @@ -1263,7 +1268,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } if (!is_anonymous) { if (size_overflow) { - ZVAL_STRING(&file_size, file_size_buf, 1); + ZVAL_STRING(&file_size, file_size_buf); } safe_php_register_variable_ex(lbuf, &file_size, NULL, size_overflow TSRMLS_CC); } @@ -1275,9 +1280,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ snprintf(lbuf, llen, "%s[size]", param); } if (size_overflow) { - ZVAL_STRING(&file_size, file_size_buf, 1); + ZVAL_STRING(&file_size, file_size_buf); } - register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, size_overflow TSRMLS_CC); + register_http_post_files_variable_ex(lbuf, &file_size, &PG(http_globals)[TRACK_VARS_FILES], size_overflow TSRMLS_CC); } efree(param); } diff --git a/main/rfc1867.h b/main/rfc1867.h index 1d47165851..ab5f50f8d6 100644 --- a/main/rfc1867.h +++ b/main/rfc1867.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -51,7 +51,7 @@ typedef struct _multipart_event_file_start { typedef struct _multipart_event_file_data { size_t post_bytes_processed; - off_t offset; + zend_off_t offset; char *data; size_t length; size_t *newlength; diff --git a/main/snprintf.c b/main/snprintf.c index 8eaf39324b..7e4d8a11ab 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -317,7 +317,7 @@ PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, c */ /* char * ap_php_conv_10() {{{ */ PHPAPI char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned, - register bool_int * is_negative, char *buf_end, register int *len) + register bool_int * is_negative, char *buf_end, register size_t *len) { register char *p = buf_end; register u_wide_int magnitude; @@ -375,7 +375,7 @@ PHPAPI char * ap_php_conv_10(register wide_int num, register bool_int is_unsigne */ /* PHPAPI char * php_conv_fp() {{{ */ PHPAPI char * php_conv_fp(register char format, register double num, - boolean_e add_dp, int precision, char dec_point, bool_int * is_negative, char *buf, int *len) + boolean_e add_dp, int precision, char dec_point, bool_int * is_negative, char *buf, size_t *len) { register char *s = buf; register char *p, *p_orig; @@ -443,7 +443,7 @@ PHPAPI char * php_conv_fp(register char format, register double num, if (format != 'F') { char temp[EXPONENT_LENGTH]; /* for exponent conversion */ - int t_len; + size_t t_len; bool_int exponent_is_negative; *s++ = format; /* either e or E */ @@ -479,7 +479,7 @@ PHPAPI char * php_conv_fp(register char format, register double num, * which is a pointer to the END of the buffer + 1 (i.e. if the buffer * is declared as buf[ 100 ], buf_end should be &buf[ 100 ]) */ -PHPAPI char * ap_php_conv_p2(register u_wide_int num, register int nbits, char format, char *buf_end, register int *len) /* {{{ */ +PHPAPI char * ap_php_conv_p2(register u_wide_int num, register int nbits, char format, char *buf_end, register size_t *len) /* {{{ */ { register int mask = (1 << nbits) - 1; register char *p = buf_end; @@ -589,10 +589,11 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / char *sp; char *bep; int cc = 0; - int i; + size_t i; char *s = NULL; - int s_len, free_zcopy; + size_t s_len; + int free_zcopy; zval *zvp, zcopy; int min_width = 0; @@ -767,6 +768,10 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / modifier = LM_SIZE_T; #endif break; + case 'p': + fmt++; + modifier = LM_PHP_INT_T; + break; case 'h': fmt++; if (*fmt == 'h') { @@ -790,9 +795,10 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / * It is reset to ' ' by non-numeric formats */ switch (*fmt) { - case 'Z': - zvp = (zval*) va_arg(ap, zval*); - zend_make_printable_zval(zvp, &zcopy, &free_zcopy); + case 'Z': { + TSRMLS_FETCH(); + zvp = (zval*) va_arg(ap, zval*); + free_zcopy = zend_make_printable_zval(zvp, &zcopy TSRMLS_CC); if (free_zcopy) { zvp = &zcopy; } @@ -800,8 +806,9 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / s = Z_STRVAL_P(zvp); if (adjust_precision && precision < s_len) { s_len = precision; - } + } break; + } case 'u': switch(modifier) { default: @@ -830,6 +837,9 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + i_num = (wide_int) va_arg(ap, zend_ulong); + break; } /* * The rest also applies to other integer formats, so fall @@ -872,6 +882,9 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + i_num = (wide_int) va_arg(ap, zend_long); + break; } } s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, @@ -918,6 +931,9 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + ui_num = (u_wide_int) va_arg(ap, zend_ulong); + break; } s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); @@ -957,6 +973,9 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + ui_num = (u_wide_int) va_arg(ap, zend_ulong); + break; } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); @@ -1239,14 +1258,14 @@ static void strx_printv(int *ccp, char *buf, size_t len, const char *format, va_ PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...) /* {{{ */ { - unsigned int cc; + int cc; va_list ap; va_start(ap, format); strx_printv(&cc, buf, len, format, ap); va_end(ap); if (cc >= len) { - cc = len -1; + cc = (int)len -1; buf[cc] = '\0'; } return cc; @@ -1255,11 +1274,11 @@ PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...) /* {{{ PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list ap) /* {{{ */ { - unsigned int cc; + int cc; strx_printv(&cc, buf, len, format, ap); if (cc >= len) { - cc = len -1; + cc = (int)len -1; buf[cc] = '\0'; } return cc; diff --git a/main/snprintf.h b/main/snprintf.h index f44659322a..115a15aa58 100644 --- a/main/snprintf.h +++ b/main/snprintf.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -31,7 +31,7 @@ sprintf offers the ability to make a lot of failures since it does not know snprintf knows the buffers size and will not write behind it. But you will have to use either a static buffer or allocate a dynamic buffer - before beeing able to call the function. In other words you must + before being able to call the function. In other words you must be sure that you really know the maximum size of the buffer required. A bad thing is having a big maximum while in most cases you would only need a small buffer. If the size of the resulting string is @@ -87,7 +87,7 @@ PHPAPI int ap_php_asprintf(char **buf, const char *format, ...); PHPAPI int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); PHPAPI char * php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf); PHPAPI char * php_conv_fp(register char format, register double num, - boolean_e add_dp, int precision, char dec_point, bool_int * is_negative, char *buf, int *len); + boolean_e add_dp, int precision, char dec_point, bool_int * is_negative, char *buf, size_t *len); END_EXTERN_C() @@ -137,7 +137,8 @@ typedef enum { #endif LM_SIZE_T, LM_LONG, - LM_LONG_DOUBLE + LM_LONG_DOUBLE, + LM_PHP_INT_T } length_modifier_e; #ifdef PHP_WIN32 @@ -153,10 +154,10 @@ typedef WIDE_INT wide_int; typedef unsigned WIDE_INT u_wide_int; PHPAPI char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned, - register bool_int * is_negative, char *buf_end, register int *len); + register bool_int * is_negative, char *buf_end, register size_t *len); PHPAPI char * ap_php_conv_p2(register u_wide_int num, register int nbits, - char format, char *buf_end, register int *len); + char format, char *buf_end, register size_t *len); /* The maximum precision that's allowed for float conversion. Does not include * decimal separator, exponent, sign, terminator. Currently does not affect diff --git a/main/spprintf.c b/main/spprintf.c index ff8e9643de..ee73d4f4e5 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -116,10 +116,40 @@ #define FLOAT_DIGITS 6 #define EXPONENT_LENGTH 10 -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" +#include "ext/standard/php_smart_string.h" /* {{{ macros */ +#define INS_CHAR(xbuf, ch, is_char) do { \ + if ((is_char)) { \ + smart_string_appendc((smart_string *)(xbuf), (ch)); \ + } else { \ + smart_str_appendc((smart_str *)(xbuf), (ch)); \ + } \ +} while (0); + +#define INS_STRING(xbuf, str, len, is_char) do { \ + if ((is_char)) { \ + smart_string_appendl((smart_string *)(xbuf), (str), (len)); \ + } else { \ + smart_str_appendl((smart_str *)(xbuf), (str), (len)); \ + } \ +} while (0); + +#define PAD_CHAR(xbuf, ch, count, is_char) do { \ + size_t newlen; \ + if ((is_char)) { \ + smart_string_alloc(((smart_string *)(xbuf)), (count), 0); \ + memset(((smart_string *)(xbuf))->c + ((smart_string *)(xbuf))->len, (ch), (count)); \ + ((smart_string *)(xbuf))->len += (count); \ + } else { \ + smart_str_alloc(((smart_str *)(xbuf)), (count), 0); \ + memset(((smart_str *)(xbuf))->s->val + ((smart_str *)(xbuf))->s->len, (ch), (count)); \ + ((smart_str *)(xbuf))->s->len += (count); \ + } \ +} while (0); + /* * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions * @@ -130,35 +160,6 @@ */ #define NUM_BUF_SIZE 2048 -/* - * The INS_CHAR macro inserts a character in the buffer. - * - * NOTE: Evaluation of the ch argument should not have any side-effects - */ -#define INS_CHAR_NR(xbuf, ch) do { \ - smart_str_appendc(xbuf, ch); \ -} while (0) - -#define INS_STRING(xbuf, s, slen) do { \ - smart_str_appendl(xbuf, s, slen); \ -} while (0) - -#define INS_CHAR(xbuf, ch) \ - INS_CHAR_NR(xbuf, ch) - -/* - * Macro that does padding. The padding is done by printing - * the character ch. - */ -#define PAD(xbuf, count, ch) do { \ - if ((count) > 0) { \ - size_t newlen; \ - smart_str_alloc(xbuf, (count), 0); \ - memset(xbuf->c + xbuf->len, ch, (count)); \ - xbuf->len += (count); \ - } \ -} while (0) - #define NUM(c) (c - '0') #define STR_TO_DEC(str, num) do { \ @@ -189,7 +190,6 @@ /* }}} */ - #if !HAVE_STRNLEN static size_t strnlen(const char *s, size_t maxlen) { char *r = memchr(s, '\0', maxlen); @@ -200,10 +200,11 @@ static size_t strnlen(const char *s, size_t maxlen) { /* * Do format conversion placing the output in buffer */ -static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) /* {{{ */ +static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt, va_list ap) /* {{{ */ { char *s = NULL; - int s_len, free_zcopy; + size_t s_len; + int free_zcopy; zval *zvp, zcopy; int min_width = 0; @@ -242,7 +243,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) while (*fmt) { if (*fmt != '%') { - INS_CHAR(xbuf, *fmt); + INS_CHAR(xbuf, *fmt, is_char); } else { /* * Default variable settings @@ -375,6 +376,16 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) modifier = LM_SIZE_T; #endif break; + case 'p': { + char __next = *(fmt+1); + if ('d' == __next || 'u' == __next || 'x' == __next || 'o' == __next) { + fmt++; + modifier = LM_PHP_INT_T; + } else { + modifier = LM_STD; + } + } + break; case 'h': fmt++; if (*fmt == 'h') { @@ -398,9 +409,10 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) * It is reset to ' ' by non-numeric formats */ switch (*fmt) { - case 'Z': + case 'Z': { + TSRMLS_FETCH(); zvp = (zval*) va_arg(ap, zval*); - zend_make_printable_zval(zvp, &zcopy, &free_zcopy); + free_zcopy = zend_make_printable_zval(zvp, &zcopy TSRMLS_CC); if (free_zcopy) { zvp = &zcopy; } @@ -410,6 +422,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) s_len = precision; } break; + } case 'u': switch(modifier) { default: @@ -438,6 +451,9 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + i_num = (wide_int) va_arg(ap, zend_ulong); + break; } /* * The rest also applies to other integer formats, so fall @@ -480,6 +496,9 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) i_num = (wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + i_num = (wide_int) va_arg(ap, zend_long); + break; } } s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, @@ -525,6 +544,9 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + ui_num = (u_wide_int) va_arg(ap, zend_ulong); + break; } s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); @@ -565,6 +587,9 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); break; #endif + case LM_PHP_INT_T: + ui_num = (u_wide_int) va_arg(ap, zend_ulong); + break; } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); @@ -717,7 +742,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) case 'n': - *(va_arg(ap, int *)) = xbuf->len; + *(va_arg(ap, int *)) = is_char? (int)((smart_string *)xbuf)->len : (int)((smart_str *)xbuf)->s->len; goto skip_output; /* @@ -781,20 +806,22 @@ fmt_error: } if (adjust_width && adjust == RIGHT && min_width > s_len) { if (pad_char == '0' && prefix_char != NUL) { - INS_CHAR(xbuf, *s); + INS_CHAR(xbuf, *s, is_char); s++; s_len--; min_width--; } - PAD(xbuf, min_width - s_len, pad_char); + PAD_CHAR(xbuf, pad_char, min_width - s_len, is_char); } /* * Print the string s. */ - INS_STRING(xbuf, s, s_len); + INS_STRING(xbuf, s, s_len, is_char); + + if (adjust_width && adjust == LEFT && min_width > s_len) { + PAD_CHAR(xbuf, pad_char, min_width - s_len, is_char); + } - if (adjust_width && adjust == LEFT && min_width > s_len) - PAD(xbuf, min_width - s_len, pad_char); if (free_zcopy) { zval_dtor(&zcopy); } @@ -809,26 +836,34 @@ skip_output: /* * This is the general purpose conversion function. */ -PHPAPI int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */ +PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */ { - smart_str xbuf = {0}; + smart_string buf = {0}; + size_t result; - xbuf_format_converter(&xbuf, format, ap); + xbuf_format_converter(&buf, 1, format, ap); - if (max_len && xbuf.len > max_len) { - xbuf.len = max_len; + if (max_len && buf.len > max_len) { + buf.len = max_len; } - smart_str_0(&xbuf); - *pbuf = xbuf.c; + smart_string_0(&buf); - return xbuf.len; + if (buf.c) { + *pbuf = buf.c; + result = buf.len; + } else { + *pbuf = NULL; + result = 0; + } + + return result; } /* }}} */ -PHPAPI int spprintf(char **pbuf, size_t max_len, const char *format, ...) /* {{{ */ +PHPAPI size_t spprintf(char **pbuf, size_t max_len, const char *format, ...) /* {{{ */ { - int cc; + size_t cc; va_list ap; va_start(ap, format); @@ -838,6 +873,33 @@ PHPAPI int spprintf(char **pbuf, size_t max_len, const char *format, ...) /* {{{ } /* }}} */ +PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */ +{ + smart_str buf = {0}; + + xbuf_format_converter(&buf, 0, format, ap); + + if (max_len && buf.s && buf.s->len > max_len) { + buf.s->len = max_len; + } + smart_str_0(&buf); + + return buf.s; +} +/* }}} */ + +PHPAPI zend_string *strpprintf(size_t max_len, const char *format, ...) /* {{{ */ +{ + va_list ap; + zend_string *str; + + va_start(ap, format); + str = vstrpprintf(max_len, format, ap); + va_end(ap); + return str; +} +/* }}} */ + /* * Local variables: * tab-width: 4 diff --git a/main/spprintf.h b/main/spprintf.h index 813bbde01a..1e7c034cfa 100644 --- a/main/spprintf.h +++ b/main/spprintf.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -37,9 +37,13 @@ There is also snprintf: See difference explained in snprintf.h #include "snprintf.h" BEGIN_EXTERN_C() -PHPAPI int spprintf( char **pbuf, size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); +PHPAPI size_t spprintf( char **pbuf, size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); -PHPAPI int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0); +PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0); + +PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap); + +PHPAPI zend_string *strpprintf(size_t max_len, const char *format, ...); END_EXTERN_C() #endif /* SNPRINTF_H */ diff --git a/main/streams/cast.c b/main/streams/cast.c index 78073c6187..3291a9ca8f 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -76,7 +76,7 @@ static int stream_cookie_writer(void *cookie, const char *buffer, int size) return php_stream_write((php_stream *)cookie, (char *)buffer, size); } -static PHP_FPOS_T stream_cookie_seeker(void *cookie, off_t position, int whence) +static PHP_FPOS_T stream_cookie_seeker(void *cookie, zend_off_t position, int whence) { TSRMLS_FETCH(); @@ -114,7 +114,7 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) { TSRMLS_FETCH(); - *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence); + *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence); if (*position == -1) { return -1; @@ -122,7 +122,7 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) return 0; } # else -static int stream_cookie_seeker(void *cookie, off_t position, int whence) +static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence) { TSRMLS_FETCH(); @@ -206,7 +206,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) { php_stream_flush(stream); if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { - off_t dummy; + zend_off_t dummy; stream->ops->seek(stream, stream->position, SEEK_SET, &dummy TSRMLS_CC); stream->readpos = stream->writepos = 0; @@ -246,7 +246,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show } if (*ret != NULL) { - off_t pos; + zend_off_t pos; stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; @@ -254,7 +254,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show * the stdio layer to believe it's real location. */ pos = php_stream_tell(stream); if (pos > 0) { - fseek(*ret, pos, SEEK_SET); + zend_fseek(*ret, pos, SEEK_SET); } goto exit_success; @@ -334,7 +334,7 @@ exit_success: * will be accessing the stream. Emit a warning so that the end-user will * know that they should try something else */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld bytes of buffered data lost during stream conversion!", (long)(stream->writepos - stream->readpos)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, ZEND_LONG_FMT " bytes of buffered data lost during stream conversion!", (zend_long)(stream->writepos - stream->readpos)); } if (castas == PHP_STREAM_AS_STDIO && ret) { diff --git a/main/streams/filter.c b/main/streams/filter.c index 71599f0d12..56e388403d 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -46,26 +46,24 @@ PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D) /* API for registering GLOBAL filters */ PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC) { - return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL); + return zend_hash_str_add_ptr(&stream_filters_hash, filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; } PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC) { - return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1); + return zend_hash_str_del(&stream_filters_hash, filterpattern, strlen(filterpattern)); } /* API for registering VOLATILE wrappers */ PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC) { if (!FG(stream_filters)) { - php_stream_filter_factory tmpfactory; - ALLOC_HASHTABLE(FG(stream_filters)); zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 1); - zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory)); + zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL); } - return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL); + return zend_hash_str_add_ptr(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; } /* Buckets */ @@ -257,9 +255,9 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval int n; char *period; - n = strlen(filtername); + n = (int)strlen(filtername); - if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n + 1, (void**)&factory)) { + if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, filtername, n))) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } else if ((period = strrchr(filtername, '.'))) { /* try a wildcard */ @@ -271,7 +269,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval while (period && !filter) { *period = '\0'; strncat(wildname, ".*", 2); - if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname) + 1, (void**)&factory)) { + if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, wildname, strlen(wildname)))) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } @@ -300,7 +298,7 @@ PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, memset(filter, 0, sizeof(php_stream_filter)); filter->fops = fops; - filter->abstract = abstract; + Z_PTR(filter->abstract) = abstract; filter->is_persistent = persistent; return filter; @@ -523,8 +521,8 @@ PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, in filter->chain->tail = filter->prev; } - if (filter->rsrc_id > 0) { - zend_list_delete(filter->rsrc_id); + if (filter->res) { + zend_list_delete(filter->res); } if (call_dtor) { diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 5a48584f4e..e62fbfb662 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -47,7 +47,7 @@ typedef struct { size_t pattern_len; } glob_s_t; -PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC) /* {{{ */ +PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, size_t *plen STREAMS_DC TSRMLS_DC) /* {{{ */ { glob_s_t *pglob = (glob_s_t *)stream->abstract; @@ -69,7 +69,7 @@ PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen S } /* }}} */ -PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC) /* {{{ */ +PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, size_t *plen STREAMS_DC TSRMLS_DC) /* {{{ */ { glob_s_t *pglob = (glob_s_t *)stream->abstract; @@ -180,7 +180,7 @@ static int php_glob_stream_close(php_stream *stream, int close_handle TSRMLS_DC) } /* {{{ */ -static int php_glob_stream_rewind(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) /* {{{ */ +static int php_glob_stream_rewind(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) /* {{{ */ { glob_s_t *pglob = (glob_s_t *)stream->abstract; diff --git a/main/streams/memory.c b/main/streams/memory.c index 81275f7797..28274d7fcd 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -20,9 +20,9 @@ #define _GNU_SOURCE #include "php.h" +#include "ext/standard/base64.h" PHPAPI int php_url_decode(char *str, int len); -PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length); /* Memory streams use a dynamic memory buffer to emulate a stream. * You can use php_stream_memory_open to create a readonly stream @@ -131,7 +131,7 @@ static int php_stream_memory_flush(php_stream *stream TSRMLS_DC) /* {{{ */ -static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract; assert(ms != NULL); @@ -355,7 +355,7 @@ typedef struct { php_stream *innerstream; size_t smax; int mode; - zval* meta; + zval meta; char* tmpdir; } php_stream_temp_data; @@ -421,9 +421,7 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC) ret = 0; } - if (ts->meta) { - zval_ptr_dtor(&ts->meta); - } + zval_ptr_dtor(&ts->meta); if (ts->tmpdir) { efree(ts->tmpdir); @@ -448,7 +446,7 @@ static int php_stream_temp_flush(php_stream *stream TSRMLS_DC) /* {{{ */ -static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_stream_temp_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract; int ret; @@ -474,7 +472,7 @@ static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRML php_stream *file; size_t memsize; char *membuf; - off_t pos; + zend_off_t pos; assert(ts != NULL); @@ -531,8 +529,8 @@ static int php_stream_temp_set_option(php_stream *stream, int option, int value, switch(option) { case PHP_STREAM_OPTION_META_DATA_API: - if (ts->meta) { - zend_hash_copy(Z_ARRVAL_P((zval*)ptrparam), Z_ARRVAL_P(ts->meta), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); + if (Z_TYPE(ts->meta) != IS_UNDEF) { + zend_hash_copy(Z_ARRVAL_P((zval*)ptrparam), Z_ARRVAL(ts->meta), zval_add_ref); } return PHP_STREAM_OPTION_RETURN_OK; default: @@ -565,6 +563,7 @@ PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, self = ecalloc(1, sizeof(*self)); self->smax = max_memory_usage; self->mode = mode; + ZVAL_UNDEF(&self->meta); if (tmpdir) { self->tmpdir = estrdup(tmpdir); } @@ -589,7 +588,7 @@ PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char { php_stream *stream; php_stream_temp_data *ts; - off_t newoffs; + zend_off_t newoffs; if ((stream = php_stream_temp_create_rel(mode, max_memory_usage)) != NULL) { if (length) { @@ -623,10 +622,12 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con php_stream_temp_data *ts; char *comma, *semi, *sep, *key; size_t mlen, dlen, plen, vlen; - off_t newoffs; - zval *meta = NULL; + zend_off_t newoffs; + zval meta; int base64 = 0, ilen; + zend_string *base64_comma = NULL; + ZVAL_NULL(&meta); if (memcmp(path, "data:", 5)) { return NULL; } @@ -656,14 +657,13 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con return NULL; } - MAKE_STD_ZVAL(meta); - array_init(meta); + array_init(&meta); if (!semi) { /* there is only a mime type */ - add_assoc_stringl(meta, "mediatype", (char *) path, mlen, 1); + add_assoc_stringl(&meta, "mediatype", (char *) path, mlen); mlen = 0; } else if (sep && sep < semi) { /* there is a mime type */ plen = semi - path; - add_assoc_stringl(meta, "mediatype", (char *) path, plen, 1); + add_assoc_stringl(&meta, "mediatype", (char *) path, plen); 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 */ @@ -693,7 +693,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con plen = sep - path; vlen = (semi ? semi - sep : mlen - plen) - 1 /* '=' */; key = estrndup(path, plen); - add_assoc_stringl_ex(meta, key, plen + 1, sep + 1, vlen, 1); + add_assoc_stringl_ex(&meta, key, plen, sep + 1, vlen); efree(key); plen += vlen + 1; mlen -= plen; @@ -705,25 +705,27 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con return NULL; } } else { - MAKE_STD_ZVAL(meta); - array_init(meta); + array_init(&meta); } - add_assoc_bool(meta, "base64", base64); + add_assoc_bool(&meta, "base64", base64); /* skip ',' */ comma++; dlen--; if (base64) { - comma = (char*)php_base64_decode((const unsigned char *)comma, dlen, &ilen); - if (!comma) { + base64_comma = php_base64_decode((const unsigned char *)comma, dlen); + if (!base64_comma) { zval_ptr_dtor(&meta); php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: unable to decode"); return NULL; } + comma = base64_comma->val; + ilen = (int)base64_comma->len; } else { comma = estrndup(comma, dlen); - ilen = dlen = php_url_decode(comma, dlen); + dlen = php_url_decode(comma, (int)dlen); + ilen = (int)dlen; } if ((stream = php_stream_temp_create_rel(0, ~0u)) != NULL) { @@ -741,9 +743,13 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con ts = (php_stream_temp_data*)stream->abstract; assert(ts != NULL); ts->mode = mode && mode[0] == 'r' && mode[1] != '+' ? TEMP_STREAM_READONLY : 0; - ts->meta = meta; + ZVAL_COPY_VALUE(&ts->meta, &meta); + } + if (base64_comma) { + zend_string_free(base64_comma); + } else { + efree(comma); } - efree(comma); return stream; } diff --git a/main/streams/mmap.c b/main/streams/mmap.c index 050e95f285..8746959bbe 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -51,7 +51,7 @@ PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC) return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0; } -PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC) +PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden TSRMLS_DC) { int ret = 1; diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h index 58b298b689..ac90a0ba3c 100644 --- a/main/streams/php_stream_context.h +++ b/main/streams/php_stream_context.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -33,34 +33,34 @@ typedef void (*php_stream_notification_func)(php_stream_context *context, If no context was passed, use the default context The default context has not yet been created, do it now. */ #define php_stream_context_from_zval(zcontext, nocontext) ( \ - (zcontext) ? zend_fetch_resource(&(zcontext) TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context(TSRMLS_C)) : \ + (zcontext) ? zend_fetch_resource(zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context(TSRMLS_C)) : \ (nocontext) ? NULL : \ FG(default_context) ? FG(default_context) : \ (FG(default_context) = php_stream_context_alloc(TSRMLS_C)) ) -#define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); zend_list_addref((context)->rsrc_id); } +#define php_stream_context_to_zval(context, zval) { ZVAL_RES(zval, (context)->res); GC_REFCOUNT((context)->res)++; } typedef struct _php_stream_notifier php_stream_notifier; struct _php_stream_notifier { php_stream_notification_func func; void (*dtor)(php_stream_notifier *notifier); - void *ptr; + zval ptr; int mask; size_t progress, progress_max; /* position for progress notification */ }; struct _php_stream_context { php_stream_notifier *notifier; - zval *options; /* hash keyed by wrapper family or specific wrapper */ - int rsrc_id; /* used for auto-cleanup */ + zval options; /* hash keyed by wrapper family or specific wrapper */ + zend_resource *res; /* used for auto-cleanup */ }; BEGIN_EXTERN_C() PHPAPI void php_stream_context_free(php_stream_context *context); PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D); -PHPAPI int php_stream_context_get_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval ***optionvalue); +PHPAPI zval *php_stream_context_get_option(php_stream_context *context, + const char *wrappername, const char *optionname); PHPAPI int php_stream_context_set_option(php_stream_context *context, const char *wrappername, const char *optionname, zval *optionvalue); @@ -87,7 +87,7 @@ END_EXTERN_C() BEGIN_EXTERN_C() PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity, char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC); -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context); +PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context TSRMLS_DC); END_EXTERN_C() #define php_stream_notify_info(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) { \ diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h index 9d9894c1c5..dfa4ae2937 100644 --- a/main/streams/php_stream_filter_api.h +++ b/main/streams/php_stream_filter_api.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -107,7 +107,7 @@ typedef struct _php_stream_filter_chain { struct _php_stream_filter { php_stream_filter_ops *fops; - void *abstract; /* for use by filter implementation */ + zval abstract; /* for use by filter implementation */ php_stream_filter *next; php_stream_filter *prev; int is_persistent; @@ -119,7 +119,7 @@ struct _php_stream_filter { php_stream_bucket_brigade buffer; /* filters are auto_registered when they're applied */ - int rsrc_id; + zend_resource *res; }; /* stack filter onto a stream */ diff --git a/main/streams/php_stream_glob_wrapper.h b/main/streams/php_stream_glob_wrapper.h index d0322f7190..69b67d4c85 100644 --- a/main/streams/php_stream_glob_wrapper.h +++ b/main/streams/php_stream_glob_wrapper.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -23,10 +23,10 @@ PHPAPI extern php_stream_ops php_glob_stream_ops; BEGIN_EXTERN_C() -PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC); +PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, size_t *plen STREAMS_DC TSRMLS_DC); #define php_glob_stream_get_path(stream, copy, plen) _php_glob_stream_get_path((stream), (copy), (plen) STREAMS_CC TSRMLS_CC) -PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC); +PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, size_t *plen STREAMS_DC TSRMLS_DC); #define php_glob_stream_get_pattern(stream, copy, plen) _php_glob_stream_get_pattern((stream), (copy), (plen) STREAMS_CC TSRMLS_CC) PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC TSRMLS_DC); diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h index b3570be48c..a25c4ac6b9 100644 --- a/main/streams/php_stream_mmap.h +++ b/main/streams/php_stream_mmap.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -74,7 +74,7 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC); #define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream) TSRMLS_CC) -PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC); +PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden TSRMLS_DC); #define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden) TSRMLS_CC) END_EXTERN_C() diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h index 4370867995..7d5278c620 100644 --- a/main/streams/php_stream_plain_wrapper.h +++ b/main/streams/php_stream_plain_wrapper.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h index dc10eb4e92..2d076064cf 100644 --- a/main/streams/php_stream_transport.h +++ b/main/streams/php_stream_transport.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -50,7 +50,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in int flags, const char *persistent_id, struct timeval *timeout, php_stream_context *context, - char **error_string, + zend_string **error_string, int *error_code STREAMS_DC TSRMLS_DC); @@ -60,7 +60,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in /* Bind the stream to a local address */ PHPAPI int php_stream_xport_bind(php_stream *stream, const char *name, size_t namelen, - char **error_text + zend_string **error_text TSRMLS_DC); /* Connect to a remote address */ @@ -68,28 +68,28 @@ PHPAPI int php_stream_xport_connect(php_stream *stream, const char *name, size_t namelen, int asynchronous, struct timeval *timeout, - char **error_text, + zend_string **error_text, int *error_code TSRMLS_DC); /* Prepare to listen */ PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, - char **error_text + zend_string **error_text TSRMLS_DC); /* Get the next client and their address as a string, or the underlying address * structure. You must efree either of these if you request them */ PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client, - char **textaddr, int *textaddrlen, + zend_string **textaddr, void **addr, socklen_t *addrlen, struct timeval *timeout, - char **error_text + zend_string **error_text TSRMLS_DC); /* Get the name of either the socket or it's peer */ PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer, - char **textaddr, int *textaddrlen, + zend_string **textaddr, void **addr, socklen_t *addrlen TSRMLS_DC); @@ -101,13 +101,13 @@ enum php_stream_xport_send_recv_flags { /* Similar to recv() system call; read data from the stream, optionally * peeking, optionally retrieving OOB data */ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen, - long flags, void **addr, socklen_t *addrlen, - char **textaddr, int *textaddrlen TSRMLS_DC); + int flags, void **addr, socklen_t *addrlen, + zend_string **textaddr TSRMLS_DC); /* Similar to send() system call; send data to the stream, optionally * sending it as OOB data */ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen, - long flags, void *addr, socklen_t addrlen TSRMLS_DC); + int flags, void *addr, socklen_t addrlen TSRMLS_DC); typedef enum { STREAM_SHUT_RD, @@ -142,23 +142,21 @@ typedef struct _php_stream_xport_param { struct { char *name; size_t namelen; - int backlog; struct timeval *timeout; struct sockaddr *addr; - socklen_t addrlen; char *buf; size_t buflen; - long flags; + socklen_t addrlen; + int backlog; + int flags; } inputs; struct { php_stream *client; - int returncode; struct sockaddr *addr; socklen_t addrlen; - char *textaddr; - long textaddrlen; - - char *error_text; + zend_string *textaddr; + zend_string *error_text; + int returncode; int error_code; } outputs; } php_stream_xport_param; @@ -193,18 +191,18 @@ PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRML END_EXTERN_C() typedef struct _php_stream_xport_crypto_param { - enum { - STREAM_XPORT_CRYPTO_OP_SETUP, - STREAM_XPORT_CRYPTO_OP_ENABLE - } op; struct { + php_stream *session; int activate; php_stream_xport_crypt_method_t method; - php_stream *session; } inputs; struct { int returncode; } outputs; + enum { + STREAM_XPORT_CRYPTO_OP_SETUP, + STREAM_XPORT_CRYPTO_OP_ENABLE + } op; } php_stream_xport_crypto_param; BEGIN_EXTERN_C() diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h index 28985a5e1e..7a03690a8f 100644 --- a/main/streams/php_stream_userspace.h +++ b/main/streams/php_stream_userspace.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h index 489e18b26f..d8799fcefb 100644 --- a/main/streams/php_streams_int.h +++ b/main/streams/php_streams_int.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 1726e4f749..8fad2aa4f1 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -54,6 +54,12 @@ extern int php_get_uid_by_name(const char *name, uid_t *uid TSRMLS_DC); extern int php_get_gid_by_name(const char *name, gid_t *gid TSRMLS_DC); #endif +#if defined(PHP_WIN32) +# define PLAIN_WRAP_BUF_SIZE(st) (((st) > UINT_MAX) ? UINT_MAX : (unsigned int)(st)) +#else +# define PLAIN_WRAP_BUF_SIZE(st) (st) +#endif + /* parse standard "fopen" modes into open() flags */ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags) { @@ -133,7 +139,7 @@ typedef struct { HANDLE file_mapping; #endif - struct stat sb; + zend_stat_t sb; } php_stdio_stream_data; #define PHP_STDIOP_GET_FD(anfd, data) anfd = (data)->file ? fileno((data)->file) : (data)->fd @@ -144,7 +150,7 @@ static int do_fstat(php_stdio_stream_data *d, int force) int r; PHP_STDIOP_GET_FD(fd, d); - r = fstat(fd, &d->sb); + r = zend_fstat(fd, &d->sb); d->cached_fstat = r == 0; return r; @@ -247,9 +253,9 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha if (self->is_pipe) { stream->flags |= PHP_STREAM_FLAG_NO_SEEK; } else { - stream->position = lseek(self->fd, 0, SEEK_CUR); + stream->position = zend_lseek(self->fd, 0, SEEK_CUR); #ifdef ESPIPE - if (stream->position == (off_t)-1 && errno == ESPIPE) { + if (stream->position == (zend_off_t)-1 && errno == ESPIPE) { stream->position = 0; stream->flags |= PHP_STREAM_FLAG_NO_SEEK; self->is_pipe = 1; @@ -286,7 +292,7 @@ PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STRE if (self->is_pipe) { stream->flags |= PHP_STREAM_FLAG_NO_SEEK; } else { - stream->position = ftell(file); + stream->position = zend_ftell(file); } } @@ -319,7 +325,11 @@ static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count assert(data != NULL); if (data->fd >= 0) { +#ifdef PHP_WIN32 + int bytes_written = write(data->fd, buf, (unsigned int)count); +#else int bytes_written = write(data->fd, buf, count); +#endif if (bytes_written < 0) return 0; return (size_t) bytes_written; } else { @@ -371,13 +381,13 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS } } #endif - ret = read(data->fd, buf, count); + ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count)); if (ret == (size_t)-1 && errno == EINTR) { /* Read was interrupted, retry once, If read still fails, giveup with feof==0 so script can retry if desired */ - ret = read(data->fd, buf, count); + ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count)); } stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK && errno != EINTR && errno != EBADF)); @@ -385,7 +395,7 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS } else { #if HAVE_FLUSHIO if (!data->is_pipe && data->last_op == 'w') - fseek(data->file, 0, SEEK_CUR); + zend_fseek(data->file, 0, SEEK_CUR); data->last_op = 'r'; #endif @@ -474,7 +484,7 @@ static int php_stdiop_flush(php_stream *stream TSRMLS_DC) return 0; } -static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) +static int php_stdiop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset TSRMLS_DC) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; int ret; @@ -487,18 +497,18 @@ static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t * } if (data->fd >= 0) { - off_t result; + zend_off_t result; - result = lseek(data->fd, offset, whence); - if (result == (off_t)-1) + result = zend_lseek(data->fd, offset, whence); + if (result == (zend_off_t)-1) return -1; *newoffset = result; return 0; } else { - ret = fseek(data->file, offset, whence); - *newoffset = ftell(data->file); + ret = zend_fseek(data->file, offset, whence); + *newoffset = zend_ftell(data->file); return ret; } } @@ -770,8 +780,8 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void GetSystemInfo(&info); gran = info.dwAllocationGranularity; - loffs = (range->offset / gran) * gran; - delta = range->offset - loffs; + loffs = ((DWORD)range->offset / gran) * gran; + delta = (DWORD)range->offset - loffs; } data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length + delta); @@ -860,7 +870,7 @@ static int php_plain_files_dirstream_close(php_stream *stream, int close_handle return closedir((DIR *)stream->abstract); } -static int php_plain_files_dirstream_rewind(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_plain_files_dirstream_rewind(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { rewinddir((DIR *)stream->abstract); return 0; @@ -1085,11 +1095,11 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f } #ifdef PHP_WIN32 - if (!php_win32_check_trailing_space(url_from, strlen(url_from))) { + if (!php_win32_check_trailing_space(url_from, (int)strlen(url_from))) { php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC); return 0; } - if (!php_win32_check_trailing_space(url_to, strlen(url_to))) { + if (!php_win32_check_trailing_space(url_to, (int)strlen(url_to))) { php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC); return 0; } @@ -1113,7 +1123,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f #ifndef PHP_WIN32 # ifdef EXDEV if (errno == EXDEV) { - struct stat sb; + zend_stat_t sb; if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) { if (VCWD_STAT(url_from, &sb) == 0) { # if !defined(TSRM_WIN32) && !defined(NETWARE) @@ -1174,8 +1184,8 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i } else { /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ char *e; - struct stat sb; - int dir_len = strlen(dir); + zend_stat_t sb; + int dir_len = (int)strlen(dir); int offset = 0; char buf[MAXPATHLEN]; @@ -1284,7 +1294,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url mode_t mode; int ret = 0; #if PHP_WIN32 - int url_len = strlen(url); + int url_len = (int)strlen(url); #endif #if PHP_WIN32 @@ -1343,7 +1353,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url break; #endif case PHP_STREAM_META_ACCESS: - mode = (mode_t)*(long *)value; + mode = (mode_t)*(zend_long *)value; ret = VCWD_CHMOD(url, mode); break; default: @@ -1373,7 +1383,7 @@ static php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_metadata }; -php_stream_wrapper php_plain_files_wrapper = { +PHPAPI php_stream_wrapper php_plain_files_wrapper = { &php_plain_files_wrapper_ops, NULL, 0 @@ -1400,7 +1410,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char return NULL; } - filename_length = strlen(filename); + filename_length = (int)strlen(filename); /* Relative path open */ if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) { @@ -1465,8 +1475,8 @@ not_relative_path: */ if (zend_is_executing(TSRMLS_C)) { exec_fname = zend_get_executed_filename(TSRMLS_C); - exec_fname_length = strlen(exec_fname); - path_length = strlen(path); + exec_fname_length = (int)strlen(exec_fname); + path_length = (int)strlen(path); while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length])); if ((exec_fname && exec_fname[0] == '[') diff --git a/main/streams/streams.c b/main/streams/streams.c index 67a151014d..c6420dc0d0 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -65,19 +65,21 @@ PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash_global(void) return &url_stream_wrappers_hash; } -static int _php_stream_release_context(zend_rsrc_list_entry *le, void *pContext TSRMLS_DC) +static int _php_stream_release_context(zval *zv, void *pContext TSRMLS_DC) { + zend_resource *le = Z_RES_P(zv); if (le->ptr == pContext) { - return --le->refcount == 0; + return --GC_REFCOUNT(le) == 0; } return 0; } -static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static int forget_persistent_resource_id_numbers(zval *el TSRMLS_DC) { php_stream *stream; + zend_resource *rsrc = Z_RES_P(el); - if (Z_TYPE_P(rsrc) != le_pstream) { + if (rsrc->type != le_pstream) { return 0; } @@ -87,13 +89,13 @@ static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRM fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); #endif - stream->rsrc_id = FAILURE; + stream->res = NULL; - if (stream->context) { + if (PHP_STREAM_CONTEXT(stream)) { zend_hash_apply_with_argument(&EG(regular_list), - (apply_func_arg_t) _php_stream_release_context, - stream->context TSRMLS_CC); - stream->context = NULL; + _php_stream_release_context, + PHP_STREAM_CONTEXT(stream) TSRMLS_CC); + stream->ctx = NULL; } return 0; @@ -101,7 +103,7 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); PHP_RSHUTDOWN_FUNCTION(streams) { - zend_hash_apply(&EG(persistent_list), (apply_func_t)forget_persistent_resource_id_numbers TSRMLS_CC); + zend_hash_apply(&EG(persistent_list), forget_persistent_resource_id_numbers TSRMLS_CC); return SUCCESS; } @@ -116,36 +118,32 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC) { - zend_rsrc_list_entry *le; + zend_resource *le; - if (zend_hash_find(&EG(persistent_list), (char*)persistent_id, strlen(persistent_id)+1, (void*) &le) == SUCCESS) { - if (Z_TYPE_P(le) == le_pstream) { + if ((le = zend_hash_str_find_ptr(&EG(persistent_list), persistent_id, strlen(persistent_id))) != NULL) { + if (le->type == le_pstream) { if (stream) { HashPosition pos; - zend_rsrc_list_entry *regentry; - ulong index = -1; /* intentional */ + zend_resource *regentry; /* see if this persistent resource already has been loaded to the * regular list; allowing the same resource in several entries in the * regular list causes trouble (see bug #54623) */ zend_hash_internal_pointer_reset_ex(&EG(regular_list), &pos); - while (zend_hash_get_current_data_ex(&EG(regular_list), - (void **)®entry, &pos) == SUCCESS) { + while ((regentry = zend_hash_get_current_data_ptr_ex(&EG(regular_list), &pos)) != NULL) { if (regentry->ptr == le->ptr) { - zend_hash_get_current_key_ex(&EG(regular_list), NULL, NULL, - &index, 0, &pos); break; } zend_hash_move_forward_ex(&EG(regular_list), &pos); } *stream = (php_stream*)le->ptr; - if (index == -1) { /* not found in regular list */ - le->refcount++; - (*stream)->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream); + if (!regentry) { /* not found in regular list */ + GC_REFCOUNT(le)++; + (*stream)->res = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream); } else { - regentry->refcount++; - (*stream)->rsrc_id = index; + GC_REFCOUNT(regentry)++; + (*stream)->res = regentry; } } return PHP_STREAM_PERSISTENT_SUCCESS; @@ -159,13 +157,10 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream * static zend_llist *php_get_wrapper_errors_list(php_stream_wrapper *wrapper TSRMLS_DC) { - zend_llist *list = NULL; if (!FG(wrapper_errors)) { return NULL; } else { - zend_hash_find(FG(wrapper_errors), (const char*)&wrapper, - sizeof wrapper, (void**)&list); - return list; + return (zend_llist*) zend_hash_str_find_ptr(FG(wrapper_errors), (const char*)&wrapper, sizeof(wrapper)); } } @@ -182,7 +177,7 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char * size_t l = 0; int brlen; int i; - int count = zend_llist_count(err_list); + int count = (int)zend_llist_count(err_list); const char *br; const char **err_buf_p; zend_llist_position pos; @@ -237,7 +232,7 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char * void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC) { if (wrapper && FG(wrapper_errors)) { - zend_hash_del(FG(wrapper_errors), (const char*)&wrapper, sizeof wrapper); + zend_hash_str_del(FG(wrapper_errors), (const char*)&wrapper, sizeof(wrapper)); } } @@ -246,6 +241,12 @@ static void wrapper_error_dtor(void *error) efree(*(char**)error); } +static void wrapper_list_dtor(zval *item) { + zend_llist *list = (zend_llist*)Z_PTR_P(item); + zend_llist_destroy(list); + efree(list); +} + PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options TSRMLS_DC, const char *fmt, ...) { va_list args; @@ -262,18 +263,16 @@ PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int option zend_llist *list = NULL; if (!FG(wrapper_errors)) { ALLOC_HASHTABLE(FG(wrapper_errors)); - zend_hash_init(FG(wrapper_errors), 8, NULL, - (dtor_func_t)zend_llist_destroy, 0); + zend_hash_init(FG(wrapper_errors), 8, NULL, wrapper_list_dtor, 0); } else { - zend_hash_find(FG(wrapper_errors), (const char*)&wrapper, - sizeof wrapper, (void**)&list); + list = zend_hash_str_find_ptr(FG(wrapper_errors), (const char*)&wrapper, sizeof(wrapper)); } if (!list) { zend_llist new_list; - zend_llist_init(&new_list, sizeof buffer, wrapper_error_dtor, 0); - zend_hash_update(FG(wrapper_errors), (const char*)&wrapper, - sizeof wrapper, &new_list, sizeof new_list, (void**)&list); + zend_llist_init(&new_list, sizeof(buffer), wrapper_error_dtor, 0); + list = zend_hash_str_update_mem(FG(wrapper_errors), (const char*)&wrapper, + sizeof(wrapper), &new_list, sizeof(new_list)); } /* append to linked list */ @@ -315,30 +314,26 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste } if (persistent_id) { - zend_rsrc_list_entry le; - - Z_TYPE(le) = le_pstream; - le.ptr = ret; - le.refcount = 0; + zval tmp; - if (FAILURE == zend_hash_update(&EG(persistent_list), (char *)persistent_id, - strlen(persistent_id) + 1, - (void *)&le, sizeof(le), NULL)) { + ZVAL_NEW_PERSISTENT_RES(&tmp, -1, ret, le_pstream); + if (NULL == zend_hash_str_update(&EG(persistent_list), persistent_id, + strlen(persistent_id), &tmp)) { pefree(ret, 1); return NULL; } } - ret->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream); + ret->res = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream); strlcpy(ret->mode, mode, sizeof(ret->mode)); ret->wrapper = NULL; ret->wrapperthis = NULL; - ret->wrapperdata = NULL; + ZVAL_UNDEF(&ret->wrapperdata); ret->stdiocast = NULL; ret->orig_path = NULL; - ret->context = NULL; + ret->ctx = NULL; ret->readbuf = NULL; ret->enclosing_stream = NULL; @@ -374,8 +369,9 @@ static const char *_php_stream_pretty_free_options(int close_options, char *out) } #endif -static int _php_stream_free_persistent(zend_rsrc_list_entry *le, void *pStream TSRMLS_DC) +static int _php_stream_free_persistent(zval *zv, void *pStream TSRMLS_DC) { + zend_resource *le = Z_RES_P(zv); return le->ptr == pStream; } @@ -391,7 +387,7 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* * already been freed (if it was created after the stream resource), so * don't reference it */ if (EG(active)) { - context = stream->context; + context = PHP_STREAM_CONTEXT(stream); } if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) { @@ -461,13 +457,19 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov _php_stream_flush(stream, 1 TSRMLS_CC); /* If not called from the resource dtor, remove the stream from the resource list. */ - if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0) { + if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0 && stream->res) { /* zend_list_delete actually only decreases the refcount; if we're * releasing the stream, we want to actually delete the resource from * the resource list, otherwise the resource will point to invalid memory. * In any case, let's always completely delete it from the resource list, * not only when PHP_STREAM_FREE_RELEASE_STREAM is set */ - while (zend_list_delete(stream->rsrc_id) == SUCCESS) {} +//??? while (zend_list_delete(stream->res) == SUCCESS) {} +//??? stream->res->gc.refcount = 0; + zend_list_close(stream->res); + if (!stream->__exposed) { + zend_list_delete(stream->res); + stream->res = NULL; + } } if (close_options & PHP_STREAM_FREE_CALL_DTOR) { @@ -507,9 +509,9 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov stream->wrapper = NULL; } - if (stream->wrapperdata) { + if (Z_TYPE(stream->wrapperdata) != IS_UNDEF) { zval_ptr_dtor(&stream->wrapperdata); - stream->wrapperdata = NULL; + ZVAL_UNDEF(&stream->wrapperdata); } if (stream->readbuf) { @@ -519,27 +521,29 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov if (stream->is_persistent && (close_options & PHP_STREAM_FREE_PERSISTENT)) { /* we don't work with *stream but need its value for comparison */ - zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _php_stream_free_persistent, stream TSRMLS_CC); + zend_hash_apply_with_argument(&EG(persistent_list), _php_stream_free_persistent, stream TSRMLS_CC); } #if ZEND_DEBUG if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) && (stream->__exposed == 0) && (EG(error_reporting) & E_WARNING)) { /* it leaked: Lets deliberately NOT pefree it so that the memory manager shows it * as leaked; it will log a warning, but lets help it out and display what kind * of stream it was. */ - char *leakinfo; - spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path); + if (!CG(unclean_shutdown)) { + char *leakinfo; + spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path); - if (stream->orig_path) { - pefree(stream->orig_path, stream->is_persistent); - stream->orig_path = NULL; - } + if (stream->orig_path) { + pefree(stream->orig_path, stream->is_persistent); + stream->orig_path = NULL; + } # if defined(PHP_WIN32) - OutputDebugString(leakinfo); + OutputDebugString(leakinfo); # else - fprintf(stderr, "%s", leakinfo); + fprintf(stderr, "%s", leakinfo); # endif - efree(leakinfo); + efree(leakinfo); + } } else { if (stream->orig_path) { pefree(stream->orig_path, stream->is_persistent); @@ -559,7 +563,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov } if (context) { - zend_list_delete(context->rsrc_id); + zend_list_delete(context->res); } return ret; @@ -671,7 +675,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D } else { /* is there enough data in the buffer ? */ - if (stream->writepos - stream->readpos < (off_t)size) { + if (stream->writepos - stream->readpos < (zend_off_t)size) { size_t justread = 0; /* reduce buffer memory consumption if possible, to avoid a realloc */ @@ -689,7 +693,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D stream->is_persistent); } - justread = stream->ops->read(stream, stream->readbuf + stream->writepos, + justread = stream->ops->read(stream, (char*)stream->readbuf + stream->writepos, stream->readbuflen - stream->writepos TSRMLS_CC); @@ -791,7 +795,7 @@ PHPAPI int _php_stream_putc(php_stream *stream, int c TSRMLS_DC) { unsigned char buf = c; - if (php_stream_write(stream, &buf, 1) > 0) { + if (php_stream_write(stream, (char*)&buf, 1) > 0) { return 1; } return EOF; @@ -809,7 +813,7 @@ PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC) PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC) { - int len; + size_t len; char newline[2] = "\n"; /* is this OK for Win? */ len = strlen(buf); @@ -839,18 +843,18 @@ PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_D return (stream->ops->stat)(stream, ssb TSRMLS_CC); } -PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC) +PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf TSRMLS_DC) { size_t avail; const char *cr, *lf, *eol = NULL; const char *readptr; if (!buf) { - readptr = stream->readbuf + stream->readpos; + readptr = (char*)stream->readbuf + stream->readpos; avail = stream->writepos - stream->readpos; } else { - readptr = buf; - avail = buf_len; + readptr = buf->val; + avail = buf->len; } /* Look for EOL */ @@ -918,8 +922,8 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, const char *eol; int done = 0; - readptr = stream->readbuf + stream->readpos; - eol = php_stream_locate_eol(stream, NULL, 0 TSRMLS_CC); + readptr = (char*)stream->readbuf + stream->readpos; + eol = php_stream_locate_eol(stream, NULL TSRMLS_CC); if (eol) { cpysz = eol - readptr + 1; @@ -1022,13 +1026,13 @@ static const char *_php_stream_search_delim(php_stream *stream, } } -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) +PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len TSRMLS_DC) { - char *ret_buf; /* returned buffer */ + zend_string *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; + int has_delim = delim_len > 0; if (maxlen == 0) { return NULL; @@ -1062,7 +1066,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re * searched for the delimiter. * The left part of the delimiter may still remain in the buffer, * so subtract up to <delim_len - 1> from buffered_len, which is - * the ammount of data we skip on this search as an optimization + * the amount of data we skip on this search as an optimization */ found_delim = _php_stream_search_delim( stream, maxlen, @@ -1097,16 +1101,16 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re } } - ret_buf = emalloc(tent_ret_len + 1); + ret_buf = zend_string_alloc(tent_ret_len, 0); /* php_stream_read will not call ops->read here because the necessary * data is guaranteedly buffered */ - *returned_len = php_stream_read(stream, ret_buf, tent_ret_len); + ret_buf->len = php_stream_read(stream, ret_buf->val, tent_ret_len); if (found_delim) { stream->readpos += delim_len; stream->position += delim_len; } - ret_buf[*returned_len] = '\0'; + ret_buf->val[ret_buf->len] = '\0'; return ret_buf; } @@ -1265,12 +1269,12 @@ PHPAPI size_t _php_stream_printf(php_stream *stream TSRMLS_DC, const char *fmt, return count; } -PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC) +PHPAPI zend_off_t _php_stream_tell(php_stream *stream TSRMLS_DC) { return stream->position; } -PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC) +PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence TSRMLS_DC) { if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) { /* flush to commit data written to the fopencookie FILE* */ @@ -1360,7 +1364,8 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi if (ret == PHP_STREAM_OPTION_RETURN_NOTIMPL) { switch(option) { case PHP_STREAM_OPTION_SET_CHUNK_SIZE: - ret = stream->chunk_size; + /* XXX chunk size itself is of size_t, that might be ok or not for a particular case*/ + ret = stream->chunk_size > INT_MAX ? INT_MAX : (int)stream->chunk_size; stream->chunk_size = value; return ret; @@ -1391,7 +1396,7 @@ PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC) { size_t bcount = 0; char buf[8192]; - int b; + size_t b; if (php_stream_mmap_possible(stream)) { char *p; @@ -1422,7 +1427,7 @@ PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC) } -PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC) +PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC) { size_t ret = 0; char *ptr; @@ -1430,9 +1435,10 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen int step = CHUNK_SIZE; int min_room = CHUNK_SIZE / 4; php_stream_statbuf ssbuf; + zend_string *result; if (maxlen == 0) { - return 0; + return STR_EMPTY_ALLOC(); } if (maxlen == PHP_STREAM_COPY_ALL) { @@ -1440,7 +1446,8 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen } if (maxlen > 0) { - ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent); + result = zend_string_alloc(maxlen, persistent); + ptr = result->val; while ((len < maxlen) && !php_stream_eof(src)) { ret = php_stream_read(src, ptr, maxlen - len); if (!ret) { @@ -1451,11 +1458,12 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen } if (len) { *ptr = '\0'; + result->len = len; } else { - pefree(*buf, persistent); - *buf = NULL; + zend_string_free(result); + result = NULL; } - return len; + return result; } /* avoid many reallocs by allocating a good sized chunk to begin with, if @@ -1470,26 +1478,28 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen max_len = step; } - ptr = *buf = pemalloc_rel_orig(max_len, persistent); + result = zend_string_alloc(max_len, persistent); + ptr = result->val; - while((ret = php_stream_read(src, ptr, max_len - len))) { + while ((ret = php_stream_read(src, ptr, max_len - len))) { len += ret; if (len + min_room >= max_len) { - *buf = perealloc_rel_orig(*buf, max_len + step, persistent); + result = zend_string_realloc(result, max_len + step, persistent); max_len += step; - ptr = *buf + len; + ptr = result->val + len; } else { ptr += ret; } } if (len) { - *buf = perealloc_rel_orig(*buf, len + 1, persistent); - (*buf)[len] = '\0'; + result = zend_string_realloc(result, len, persistent); + result->val[len] = '\0'; } else { - pefree(*buf, persistent); - *buf = NULL; + zend_string_free(result); + result = NULL; } - return len; + + return result; } /* Returns SUCCESS/FAILURE and sets *len to the number of bytes moved */ @@ -1613,14 +1623,14 @@ PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size /* {{{ wrapper init and registration */ -static void stream_resource_regular_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void stream_resource_regular_dtor(zend_resource *rsrc TSRMLS_DC) { php_stream *stream = (php_stream*)rsrc->ptr; /* set the return value for pclose */ FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); } -static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void stream_resource_persistent_dtor(zend_resource *rsrc TSRMLS_DC) { php_stream *stream = (php_stream*)rsrc->ptr; FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); @@ -1655,14 +1665,11 @@ int php_init_stream_wrappers(int module_number TSRMLS_DC) /* Filters are cleaned up by the streams they're attached to */ le_stream_filter = zend_register_list_destructors_ex(NULL, NULL, "stream filter", module_number); - return ( - zend_hash_init(&url_stream_wrappers_hash, 0, NULL, NULL, 1) == SUCCESS - && - zend_hash_init(php_get_stream_filters_hash_global(), 0, NULL, NULL, 1) == SUCCESS - && - zend_hash_init(php_stream_xport_get_hash(), 0, NULL, NULL, 1) == SUCCESS - && - php_stream_xport_register("tcp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS + zend_hash_init(&url_stream_wrappers_hash, 8, NULL, NULL, 1); + zend_hash_init(php_get_stream_filters_hash_global(), 8, NULL, NULL, 1); + zend_hash_init(php_stream_xport_get_hash(), 8, NULL, NULL, 1); + + return (php_stream_xport_register("tcp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS && php_stream_xport_register("udp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS #if defined(AF_UNIX) && !(defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE)) @@ -1704,33 +1711,31 @@ static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsig /* API for registering GLOBAL wrappers */ PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) { - unsigned int protocol_len = strlen(protocol); + unsigned int protocol_len = (unsigned int)strlen(protocol); if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) { return FAILURE; } - return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); + return zend_hash_str_add_ptr(&url_stream_wrappers_hash, protocol, protocol_len, wrapper) ? SUCCESS : FAILURE; } PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC) { - return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1); + return zend_hash_str_del(&url_stream_wrappers_hash, protocol, strlen(protocol)); } static void clone_wrapper_hash(TSRMLS_D) { - php_stream_wrapper *tmp; - ALLOC_HASHTABLE(FG(stream_wrappers)); zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 1); - zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmp, sizeof(tmp)); + zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL); } /* API for registering VOLATILE wrappers */ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC) { - unsigned int protocol_len = strlen(protocol); + unsigned int protocol_len = (unsigned int)strlen(protocol); if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) { return FAILURE; @@ -1740,7 +1745,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_st clone_wrapper_hash(TSRMLS_C); } - return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); + return zend_hash_str_add_ptr(FG(stream_wrappers), protocol, protocol_len, wrapper) ? SUCCESS : FAILURE; } PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC) @@ -1749,7 +1754,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRML clone_wrapper_hash(TSRMLS_C); } - return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1); + return zend_hash_str_del(FG(stream_wrappers), protocol, strlen(protocol)); } /* }}} */ @@ -1757,7 +1762,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRML 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; + php_stream_wrapper *wrapper = NULL; const char *p, *protocol = NULL; int n = 0; @@ -1784,9 +1789,9 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const if (protocol) { char *tmp = estrndup(protocol, n); - if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) { + if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) { php_strtolower(tmp, n); - if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) { + if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) { @@ -1796,7 +1801,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name); - wrapperpp = NULL; + wrapper = NULL; protocol = NULL; } } @@ -1846,14 +1851,14 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const if (FG(stream_wrappers)) { /* The file:// wrapper may have been disabled/overridden */ - if (wrapperpp) { + if (wrapper) { /* It was found so go ahead and provide it */ - return *wrapperpp; + return wrapper; } /* Check again, the original check might have not known the protocol name */ - if (zend_hash_find(wrapper_hash, "file", sizeof("file"), (void**)&wrapperpp) == SUCCESS) { - return *wrapperpp; + if ((wrapper = zend_hash_str_find_ptr(wrapper_hash, "file", sizeof("file")-1)) != NULL) { + return wrapper; } if (options & REPORT_ERRORS) { @@ -1865,7 +1870,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const return plain_files_wrapper; } - if (wrapperpp && (*wrapperpp)->is_url && + if (wrapper && wrapper->is_url && (options & STREAM_DISABLE_URL_PROTECTION) == 0 && (!PG(allow_url_fopen) || (((options & STREAM_OPEN_FOR_INCLUDE) || @@ -1883,7 +1888,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const return NULL; } - return *wrapperpp; + return wrapper; } /* }}} */ @@ -2036,7 +2041,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod } if (options & USE_PATH) { - resolved_path = zend_resolve_path(path, strlen(path) TSRMLS_CC); + resolved_path = zend_resolve_path(path, (int)strlen(path) TSRMLS_CC); if (resolved_path) { path = resolved_path; /* we've found this file, don't re-check include_path or run realpath */ @@ -2132,7 +2137,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod } if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a') && stream->position == 0) { - off_t newpos = 0; + zend_off_t newpos = 0; /* if opened for append, we need to revise our idea of the initial file position */ if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos TSRMLS_CC)) { @@ -2161,18 +2166,18 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod /* }}} */ /* {{{ context API */ -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context) +PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context TSRMLS_DC) { - php_stream_context *oldcontext = stream->context; - TSRMLS_FETCH(); - - stream->context = context; + php_stream_context *oldcontext = PHP_STREAM_CONTEXT(stream); if (context) { - zend_list_addref(context->rsrc_id); + stream->ctx = context->res; + GC_REFCOUNT(context->res)++; + } else { + stream->ctx = NULL; } if (oldcontext) { - zend_list_delete(oldcontext->rsrc_id); + zend_list_delete(oldcontext->res); } return oldcontext; @@ -2187,9 +2192,9 @@ PHPAPI void php_stream_notification_notify(php_stream_context *context, int noti PHPAPI void php_stream_context_free(php_stream_context *context) { - if (context->options) { + if (Z_TYPE(context->options) != IS_UNDEF) { zval_ptr_dtor(&context->options); - context->options = NULL; + ZVAL_UNDEF(&context->options); } if (context->notifier) { php_stream_notification_free(context->notifier); @@ -2204,10 +2209,9 @@ PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D) context = ecalloc(1, sizeof(php_stream_context)); context->notifier = NULL; - MAKE_STD_ZVAL(context->options); - array_init(context->options); + array_init(&context->options); - context->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context(TSRMLS_C)); + context->res = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context(TSRMLS_C)); return context; } @@ -2224,65 +2228,61 @@ PHPAPI void php_stream_notification_free(php_stream_notifier *notifier) efree(notifier); } -PHPAPI int php_stream_context_get_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval ***optionvalue) +PHPAPI zval *php_stream_context_get_option(php_stream_context *context, + const char *wrappername, const char *optionname) { - zval **wrapperhash; + zval *wrapperhash; - if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) { - return FAILURE; + if (NULL == (wrapperhash = zend_hash_str_find(Z_ARRVAL(context->options), wrappername, strlen(wrappername)))) { + return NULL; } - return zend_hash_find(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)optionvalue); + return zend_hash_str_find(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname)); } PHPAPI int php_stream_context_set_option(php_stream_context *context, const char *wrappername, const char *optionname, zval *optionvalue) { - zval **wrapperhash; - zval *category, *copied_val; + zval *wrapperhash; + zval category, copied_val; - ALLOC_INIT_ZVAL(copied_val); - *copied_val = *optionvalue; - zval_copy_ctor(copied_val); - INIT_PZVAL(copied_val); + ZVAL_DUP(&copied_val, optionvalue); - if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) { - MAKE_STD_ZVAL(category); - array_init(category); - if (FAILURE == zend_hash_update(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&category, sizeof(zval *), NULL)) { + if (NULL == (wrapperhash = zend_hash_str_find(Z_ARRVAL(context->options), wrappername, strlen(wrappername)))) { + array_init(&category); + if (NULL == zend_hash_str_update(Z_ARRVAL(context->options), (char*)wrappername, strlen(wrappername), &category)) { return FAILURE; } wrapperhash = &category; } - return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL); + return zend_hash_str_update(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname), &copied_val) ? SUCCESS : FAILURE; } /* }}} */ /* {{{ php_stream_dirent_alphasort */ -PHPAPI int php_stream_dirent_alphasort(const char **a, const char **b) +PHPAPI int php_stream_dirent_alphasort(const zend_string **a, const zend_string **b) { - return strcoll(*a, *b); + return strcoll((*a)->val, (*b)->val); } /* }}} */ /* {{{ php_stream_dirent_alphasortr */ -PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b) +PHPAPI int php_stream_dirent_alphasortr(const zend_string **a, const zend_string **b) { - return strcoll(*b, *a); + return strcoll((*b)->val, (*a)->val); } /* }}} */ /* {{{ php_stream_scandir */ -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) +PHPAPI int _php_stream_scandir(const char *dirname, zend_string **namelist[], int flags, php_stream_context *context, + int (*compare) (const zend_string **a, const zend_string **b) TSRMLS_DC) { php_stream *stream; php_stream_dirent sdp; - char **vector = NULL; + zend_string **vector = NULL; unsigned int vector_size = 0; unsigned int nfiles = 0; @@ -2308,10 +2308,10 @@ PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags } vector_size *= 2; } - vector = (char **) safe_erealloc(vector, vector_size, sizeof(char *), 0); + vector = (zend_string **) safe_erealloc(vector, vector_size, sizeof(char *), 0); } - vector[nfiles] = estrdup(sdp.d_name); + vector[nfiles] = zend_string_init(sdp.d_name, strlen(sdp.d_name), 0); nfiles++; if(vector_size < 10 || nfiles == 0) { @@ -2326,7 +2326,7 @@ PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags *namelist = vector; if (nfiles > 0 && compare) { - qsort(*namelist, nfiles, sizeof(char *), (int(*)(const void *, const void *))compare); + qsort(*namelist, nfiles, sizeof(zend_string *), (int(*)(const void *, const void *))compare); } return nfiles; } diff --git a/main/streams/transports.c b/main/streams/transports.c index a633b059fa..8fd0b91d35 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -31,37 +31,37 @@ PHPAPI HashTable *php_stream_xport_get_hash(void) 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); + return zend_hash_str_update_ptr(&xport_hash, protocol, strlen(protocol), factory) ? SUCCESS : FAILURE; } PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC) { - return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1); + return zend_hash_str_del(&xport_hash, protocol, strlen(protocol)); } #define ERR_REPORT(out_err, fmt, arg) \ - if (out_err) { spprintf(out_err, 0, fmt, arg); } \ + if (out_err) { *out_err = strpprintf(0, fmt, arg); } \ else { php_error_docref(NULL TSRMLS_CC, E_WARNING, fmt, arg); } #define ERR_RETURN(out_err, local_err, fmt) \ if (out_err) { *out_err = local_err; } \ - else { php_error_docref(NULL TSRMLS_CC, E_WARNING, fmt, local_err ? local_err : "Unspecified error"); \ - if (local_err) { efree(local_err); local_err = NULL; } \ + else { php_error_docref(NULL TSRMLS_CC, E_WARNING, fmt, local_err ? local_err->val : "Unspecified error"); \ + if (local_err) { zend_string_release(local_err); local_err = NULL; } \ } 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, - char **error_string, + zend_string **error_string, int *error_code STREAMS_DC TSRMLS_DC) { php_stream *stream = NULL; - php_stream_transport_factory *factory = NULL; + php_stream_transport_factory factory = NULL; const char *p, *protocol = NULL; int n = 0, failed = 0; - char *error_text = NULL; + zend_string *error_text = NULL; struct timeval default_timeout = { 0, 0 }; default_timeout.tv_sec = FG(default_socket_timeout); @@ -107,7 +107,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in if (protocol) { char *tmp = estrndup(protocol, n); - if (FAILURE == zend_hash_find(&xport_hash, (char*)tmp, n + 1, (void**)&factory)) { + if (NULL == (factory = zend_hash_str_find_ptr(&xport_hash, tmp, n))) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) @@ -129,12 +129,12 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in return NULL; } - stream = (*factory)(protocol, n, + stream = (factory)(protocol, n, (char*)name, namelen, persistent_id, options, flags, timeout, context STREAMS_REL_CC TSRMLS_CC); if (stream) { - php_stream_context_set(stream, context); + php_stream_context_set(stream, context TSRMLS_CC); if ((flags & STREAM_XPORT_SERVER) == 0) { /* client */ @@ -157,16 +157,16 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in ERR_RETURN(error_string, error_text, "bind() failed: %s"); failed = 1; } else if (flags & STREAM_XPORT_LISTEN) { - zval **zbacklog = NULL; + zval *zbacklog = NULL; int backlog = 32; - if (stream->context && php_stream_context_get_option(stream->context, "socket", "backlog", &zbacklog) == SUCCESS) { - zval *ztmp = *zbacklog; + if (PHP_STREAM_CONTEXT(stream) && (zbacklog = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "backlog")) != NULL) { + zval *ztmp = zbacklog; - convert_to_long_ex(&ztmp); + convert_to_long_ex(ztmp); backlog = Z_LVAL_P(ztmp); - if (ztmp != *zbacklog) { - zval_ptr_dtor(&ztmp); + if (ztmp != zbacklog) { + zval_ptr_dtor(ztmp); } } @@ -195,7 +195,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in /* Bind the stream to a local address */ PHPAPI int php_stream_xport_bind(php_stream *stream, const char *name, size_t namelen, - char **error_text + zend_string **error_text TSRMLS_DC) { php_stream_xport_param param; @@ -225,7 +225,7 @@ PHPAPI int php_stream_xport_connect(php_stream *stream, const char *name, size_t namelen, int asynchronous, struct timeval *timeout, - char **error_text, + zend_string **error_text, int *error_code TSRMLS_DC) { @@ -257,7 +257,7 @@ PHPAPI int php_stream_xport_connect(php_stream *stream, } /* Prepare to listen */ -PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, char **error_text TSRMLS_DC) +PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, zend_string **error_text TSRMLS_DC) { php_stream_xport_param param; int ret; @@ -282,10 +282,10 @@ PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, char **error /* Get the next client and their address (as a string) */ PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client, - char **textaddr, int *textaddrlen, + zend_string **textaddr, void **addr, socklen_t *addrlen, struct timeval *timeout, - char **error_text + zend_string **error_text TSRMLS_DC) { php_stream_xport_param param; @@ -309,7 +309,6 @@ PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client, } if (textaddr) { *textaddr = param.outputs.textaddr; - *textaddrlen = param.outputs.textaddrlen; } if (error_text) { *error_text = param.outputs.error_text; @@ -321,7 +320,7 @@ PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client, } PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer, - char **textaddr, int *textaddrlen, + zend_string **textaddr, void **addr, socklen_t *addrlen TSRMLS_DC) { @@ -343,7 +342,6 @@ PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer, } if (textaddr) { *textaddr = param.outputs.textaddr; - *textaddrlen = param.outputs.textaddrlen; } return param.outputs.returncode; @@ -395,7 +393,7 @@ PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRML /* Similar to recv() system call; read data from the stream, optionally * peeking, optionally retrieving OOB data */ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen, - long flags, void **addr, socklen_t *addrlen, char **textaddr, int *textaddrlen + int flags, void **addr, socklen_t *addrlen, zend_string **textaddr TSRMLS_DC) { php_stream_xport_param param; @@ -455,7 +453,6 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle } if (textaddr) { *textaddr = param.outputs.textaddr; - *textaddrlen = param.outputs.textaddrlen; } return recvd_len + param.outputs.returncode; } @@ -465,7 +462,7 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle /* Similar to send() system call; send data to the stream, optionally * sending it as OOB data */ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen, - long flags, void *addr, socklen_t addrlen TSRMLS_DC) + int flags, void *addr, socklen_t addrlen TSRMLS_DC) { php_stream_xport_param param; int ret = 0; diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 5990464a6e..1ff80cdfa6 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -70,7 +70,7 @@ static php_stream_wrapper_ops user_stream_wops = { }; -static void stream_wrapper_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void stream_wrapper_dtor(zend_resource *rsrc TSRMLS_DC) { struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper*)rsrc->ptr; @@ -120,7 +120,7 @@ PHP_MINIT_FUNCTION(user_streams) struct _php_userstream_data { struct php_user_stream_wrapper * wrapper; - zval * object; + zval object; }; typedef struct _php_userstream_data php_userstream_data_t; @@ -281,18 +281,14 @@ typedef struct _php_userstream_data php_userstream_data_t; }}} **/ -static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context TSRMLS_DC) +static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context, zval *object TSRMLS_DC) { - zval *object; /* create an instance of our class */ - ALLOC_ZVAL(object); object_init_ex(object, uwrap->ce); - Z_SET_REFCOUNT_P(object, 1); - Z_SET_ISREF_P(object); if (context) { - add_property_resource(object, "context", context->rsrc_id); - zend_list_addref(context->rsrc_id); + add_property_resource(object, "context", context->res); + GC_REFCOUNT(context->res)++; } else { add_property_null(object, "context"); } @@ -300,14 +296,14 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph if (uwrap->ce->constructor) { zend_fcall_info fci; zend_fcall_info_cache fcc; - zval *retval_ptr; + zval retval; fci.size = sizeof(fci); fci.function_table = &uwrap->ce->function_table; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = object; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = Z_OBJ_P(object); + fci.retval = &retval; fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; @@ -316,20 +312,16 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph fcc.function_handler = uwrap->ce->constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(object); - fcc.object_ptr = object; + fcc.object = Z_OBJ_P(object); if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name, uwrap->ce->constructor->common.function_name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name->val, uwrap->ce->constructor->common.function_name->val); zval_dtor(object); - FREE_ZVAL(object); - return NULL; + ZVAL_UNDEF(object); } else { - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } + zval_ptr_dtor(&retval); } } - return object; } static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, @@ -337,8 +329,8 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; php_userstream_data_t *us; - zval *zfilename, *zmode, *zopened, *zoptions, *zretval = NULL, *zfuncname; - zval **args[4]; + zval zretval, zfuncname; + zval args[4]; int call_result; php_stream *stream = NULL; zend_bool old_in_user_include; @@ -364,8 +356,8 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * us = emalloc(sizeof(*us)); us->wrapper = uwrap; - us->object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(us->object == NULL) { + user_stream_create_object(uwrap, context, &us->object TSRMLS_CC); + if (Z_TYPE(us->object) == IS_UNDEF) { FG(user_stream_current_filename) = NULL; PG(in_user_include) = old_in_user_include; efree(us); @@ -373,46 +365,31 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * } /* call it's stream_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, filename, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zmode); - ZVAL_STRING(zmode, mode, 1); - args[1] = &zmode; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[2] = &zoptions; + ZVAL_STRING(&args[0], filename); + ZVAL_STRING(&args[1], mode); + ZVAL_LONG(&args[2], options); + ZVAL_NEW_REF(&args[3], &EG(uninitialized_zval)); - MAKE_STD_ZVAL(zopened); - Z_SET_REFCOUNT_P(zopened, 1); - Z_SET_ISREF_P(zopened); - ZVAL_NULL(zopened); - args[3] = &zopened; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_OPEN, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_OPEN); call_result = call_user_function_ex(NULL, - &us->object, - zfuncname, + Z_ISUNDEF(us->object)? NULL : &us->object, + &zfuncname, &zretval, 4, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { + if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) { /* the stream is now open! */ stream = php_stream_alloc_rel(&php_stream_userspace_ops, us, 0, mode); /* if the opened path is set, copy it out */ - if (Z_TYPE_P(zopened) == IS_STRING && opened_path) { - *opened_path = estrndup(Z_STRVAL_P(zopened), Z_STRLEN_P(zopened)); + if (Z_ISREF(args[3]) && Z_TYPE_P(Z_REFVAL(args[3])) == IS_STRING && opened_path) { + *opened_path = estrndup(Z_STRVAL_P(Z_REFVAL(args[3])), Z_STRLEN_P(Z_REFVAL(args[3]))); } /* set wrapper data to be a reference to our object */ - stream->wrapperdata = us->object; - zval_add_ref(&stream->wrapperdata); + ZVAL_COPY(&stream->wrapperdata, &us->object); } else { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_OPEN "\" call failed", us->wrapper->classname); @@ -421,16 +398,15 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * /* destroy everything else */ if (stream == NULL) { zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&us->object); efree(us); } - if (zretval) - zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zopened); - zval_ptr_dtor(&zoptions); - zval_ptr_dtor(&zmode); - zval_ptr_dtor(&zfilename); + zval_ptr_dtor(&args[3]); + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); FG(user_stream_current_filename) = NULL; @@ -443,8 +419,8 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; php_userstream_data_t *us; - zval *zfilename, *zoptions, *zretval = NULL, *zfuncname; - zval **args[2]; + zval zretval, zfuncname; + zval args[2]; int call_result; php_stream *stream = NULL; @@ -458,39 +434,32 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char us = emalloc(sizeof(*us)); us->wrapper = uwrap; - us->object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(us->object == NULL) { + user_stream_create_object(uwrap, context, &us->object TSRMLS_CC); + if (Z_TYPE(us->object) == IS_UNDEF) { FG(user_stream_current_filename) = NULL; efree(us); return NULL; } /* call it's dir_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, filename, 1); - args[0] = &zfilename; + ZVAL_STRING(&args[0], filename); + ZVAL_LONG(&args[1], options); - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_DIR_OPEN, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_DIR_OPEN); call_result = call_user_function_ex(NULL, - &us->object, - zfuncname, + Z_ISUNDEF(us->object)? NULL : &us->object, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { + if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) { /* the stream is now open! */ stream = php_stream_alloc_rel(&php_stream_userspace_dir_ops, us, 0, mode); /* set wrapper data to be a reference to our object */ - stream->wrapperdata = us->object; - zval_add_ref(&stream->wrapperdata); + ZVAL_COPY(&stream->wrapperdata, &us->object); } else { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed", us->wrapper->classname); @@ -499,14 +468,14 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char /* destroy everything else */ if (stream == NULL) { zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&us->object); efree(us); } - if (zretval) - zval_ptr_dtor(&zretval); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zoptions); - zval_ptr_dtor(&zfilename); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); FG(user_stream_current_filename) = NULL; @@ -518,43 +487,41 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char Registers a custom URL protocol handler class */ PHP_FUNCTION(stream_wrapper_register) { - char *protocol, *classname; - int protocol_len, classname_len; + zend_string *protocol, *classname; struct php_user_stream_wrapper * uwrap; - int rsrc_id; - long flags = 0; + zend_resource *rsrc; + zend_long flags = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &protocol, &protocol_len, &classname, &classname_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|l", &protocol, &classname, &flags) == FAILURE) { RETURN_FALSE; } uwrap = (struct php_user_stream_wrapper *)ecalloc(1, sizeof(*uwrap)); - uwrap->protoname = estrndup(protocol, protocol_len); - uwrap->classname = estrndup(classname, classname_len); + uwrap->protoname = estrndup(protocol->val, protocol->len); + uwrap->classname = estrndup(classname->val, classname->len); uwrap->wrapper.wops = &user_stream_wops; uwrap->wrapper.abstract = uwrap; uwrap->wrapper.is_url = ((flags & PHP_STREAM_IS_URL) != 0); - rsrc_id = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols); + rsrc = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols); - if (zend_lookup_class(uwrap->classname, classname_len, (zend_class_entry***)&uwrap->ce TSRMLS_CC) == SUCCESS) { - uwrap->ce = *(zend_class_entry**)uwrap->ce; - if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper TSRMLS_CC) == SUCCESS) { + if ((uwrap->ce = zend_lookup_class(classname TSRMLS_CC)) != NULL) { + if (php_register_url_stream_wrapper_volatile(protocol->val, &uwrap->wrapper TSRMLS_CC) == SUCCESS) { RETURN_TRUE; } else { /* We failed. But why? */ - if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len + 1)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol); + if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol->val); } else { /* Hash doesn't exist so it must have been an invalid protocol scheme */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", classname, protocol); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", classname->val, protocol->val); } } } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", classname); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", classname->val); } - zend_list_delete(rsrc_id); + zend_list_delete(rsrc); RETURN_FALSE; } /* }}} */ @@ -564,7 +531,7 @@ PHP_FUNCTION(stream_wrapper_register) PHP_FUNCTION(stream_wrapper_unregister) { char *protocol; - int protocol_len; + size_t protocol_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) { RETURN_FALSE; @@ -584,34 +551,30 @@ PHP_FUNCTION(stream_wrapper_unregister) Restore the original protocol handler, overriding if necessary */ PHP_FUNCTION(stream_wrapper_restore) { - char *protocol; - int protocol_len; - php_stream_wrapper **wrapperpp = NULL, *wrapper; + zend_string *protocol; + php_stream_wrapper *wrapper; HashTable *global_wrapper_hash; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &protocol) == FAILURE) { RETURN_FALSE; } global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global(); if (php_stream_get_url_stream_wrappers_hash() == global_wrapper_hash) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s:// was never changed, nothing to restore", protocol); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s:// was never changed, nothing to restore", protocol->val); RETURN_TRUE; } - if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len + 1, (void**)&wrapperpp) == FAILURE) || !wrapperpp) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol); + if ((wrapper = zend_hash_find_ptr(global_wrapper_hash, protocol)) == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol->val); RETURN_FALSE; } - /* next line might delete the pointer that wrapperpp points at, so deref it now */ - wrapper = *wrapperpp; - /* A failure here could be okay given that the protocol might have been merely unregistered */ - php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC); + php_unregister_url_stream_wrapper_volatile(protocol->val TSRMLS_CC); - if (php_register_url_stream_wrapper_volatile(protocol, wrapper TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to restore original %s:// wrapper", protocol); + if (php_register_url_stream_wrapper_volatile(protocol->val, wrapper TSRMLS_CC) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to restore original %s:// wrapper", protocol->val); RETURN_FALSE; } @@ -622,33 +585,31 @@ PHP_FUNCTION(stream_wrapper_restore) static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval **args[1]; - zval *zbufptr; + zval args[1]; size_t didwrite = 0; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1); - MAKE_STD_ZVAL(zbufptr); - ZVAL_STRINGL(zbufptr, (char*)buf, count, 1);; - args[0] = &zbufptr; + ZVAL_STRINGL(&args[0], (char*)buf, count); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); - zval_ptr_dtor(&zbufptr); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&func_name); didwrite = 0; - if (call_result == SUCCESS && retval != NULL) { - convert_to_long(retval); - didwrite = Z_LVAL_P(retval); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + convert_to_long(&retval); + didwrite = Z_LVAL(retval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!", us->wrapper->classname); @@ -656,14 +617,13 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t /* don't allow strange buffer overruns due to bogus return */ if (didwrite > count) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " wrote %ld bytes more data than requested (%ld written, %ld max)", + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " wrote " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " written, " ZEND_LONG_FMT " max)", us->wrapper->classname, - (long)(didwrite - count), (long)didwrite, (long)count); + (zend_long)(didwrite - count), (zend_long)didwrite, (zend_long)count); didwrite = count; } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return didwrite; } @@ -671,60 +631,56 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { zval func_name; - zval *retval = NULL; - zval **args[1]; + zval retval; + zval args[1]; int call_result; size_t didread = 0; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval *zcount; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1); - MAKE_STD_ZVAL(zcount); - ZVAL_LONG(zcount, count); - args[0] = &zcount; + ZVAL_LONG(&args[0], count); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL) { - convert_to_string(retval); - didread = Z_STRLEN_P(retval); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + convert_to_string(&retval); + didread = Z_STRLEN(retval); if (didread > count) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " - read %ld bytes more data than requested (%ld read, %ld max) - excess data will be lost", - us->wrapper->classname, (long)(didread - count), (long)didread, (long)count); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost", + us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count); didread = count; } if (didread > 0) - memcpy(buf, Z_STRVAL_P(retval), didread); + memcpy(buf, Z_STRVAL(retval), didread); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!", us->wrapper->classname); } - zval_ptr_dtor(&zcount); + zval_ptr_dtor(&args[0]); - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } + zval_ptr_dtor(&retval); + ZVAL_UNDEF(&retval); + zval_ptr_dtor(&func_name); /* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */ - ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) { + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) { stream->eof = 1; } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, @@ -734,10 +690,8 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count stream->eof = 1; } - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return didread; } @@ -745,23 +699,24 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1); call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&us->object); efree(us); @@ -771,97 +726,89 @@ static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC static int php_userstreamop_flush(php_stream *stream TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) call_result = 0; else call_result = -1; - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return call_result; } -static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result, ret; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval **args[2]; - zval *zoffs, *zwhence; + zval args[2]; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1); - MAKE_STD_ZVAL(zoffs); - ZVAL_LONG(zoffs, offset); - args[0] = &zoffs; - - MAKE_STD_ZVAL(zwhence); - ZVAL_LONG(zwhence, whence); - args[1] = &zwhence; + ZVAL_LONG(&args[0], offset); + ZVAL_LONG(&args[1], whence); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 2, args, 0, NULL TSRMLS_CC); - zval_ptr_dtor(&zoffs); - zval_ptr_dtor(&zwhence); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&func_name); if (call_result == FAILURE) { /* stream_seek is not implemented, so disable seeks for this stream */ stream->flags |= PHP_STREAM_FLAG_NO_SEEK; /* there should be no retval to clean up */ - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return -1; - } else if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) { + } else if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) { ret = 0; } else { ret = -1; } - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } + zval_ptr_dtor(&retval); + ZVAL_UNDEF(&retval); if (ret) { return ret; } /* now determine where we are */ - ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG) { - *newoffs = Z_LVAL_P(retval); + if (call_result == SUCCESS && Z_TYPE(retval) == IS_LONG) { + *newoffs = Z_LVAL(retval); ret = 0; } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname); @@ -870,9 +817,8 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o ret = -1; } - if (retval) { - zval_ptr_dtor(&retval); - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return ret; } @@ -880,13 +826,13 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o * relevant fields into the statbuf provided */ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) { - zval **elem; + zval *elem; #define STAT_PROP_ENTRY_EX(name, name2) \ - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(array), #name, sizeof(#name), (void**)&elem)) { \ + if (NULL != (elem = zend_hash_str_find(Z_ARRVAL_P(array), #name, sizeof(#name)-1))) { \ SEPARATE_ZVAL(elem); \ - convert_to_long(*elem); \ - ssb->sb.st_##name2 = Z_LVAL_PP(elem); \ + convert_to_long(elem); \ + ssb->sb.st_##name2 = Z_LVAL_P(elem); \ } #define STAT_PROP_ENTRY(name) STAT_PROP_ENTRY_EX(name,name) @@ -926,21 +872,21 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; int ret = -1; - ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_ARRAY) { - if (SUCCESS == statbuf_from_array(retval, ssb TSRMLS_CC)) + if (call_result == SUCCESS && Z_TYPE(retval) == IS_ARRAY) { + if (SUCCESS == statbuf_from_array(&retval, ssb TSRMLS_CC)) ret = 0; } else { if (call_result == FAILURE) { @@ -949,8 +895,8 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSR } } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return ret; } @@ -958,59 +904,57 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSR static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL; - zval *zvalue = NULL; - zval **args[3]; + zval args[3]; switch (option) { case PHP_STREAM_OPTION_CHECK_LIVENESS: - ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0); - call_result = call_user_function_ex(NULL, &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) { - ret = zval_is_true(retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; + ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1); + call_result = call_user_function_ex(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); + if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) { + ret = zval_is_true(&retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; } else { ret = PHP_STREAM_OPTION_RETURN_ERR; php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_EOF " is not implemented! Assuming EOF", us->wrapper->classname); } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); break; case PHP_STREAM_OPTION_LOCKING: - MAKE_STD_ZVAL(zvalue); - ZVAL_LONG(zvalue, 0); + ZVAL_LONG(&args[0], 0); if (value & LOCK_NB) { - Z_LVAL_P(zvalue) |= PHP_LOCK_NB; + Z_LVAL_P(&args[0]) |= PHP_LOCK_NB; } switch(value & ~LOCK_NB) { case LOCK_SH: - Z_LVAL_P(zvalue) |= PHP_LOCK_SH; + Z_LVAL_P(&args[0]) |= PHP_LOCK_SH; break; case LOCK_EX: - Z_LVAL_P(zvalue) |= PHP_LOCK_EX; + Z_LVAL_P(&args[0]) |= PHP_LOCK_EX; break; case LOCK_UN: - Z_LVAL_P(zvalue) |= PHP_LOCK_UN; + Z_LVAL_P(&args[0]) |= PHP_LOCK_UN; break; } - args[0] = &zvalue; - /* TODO wouldblock */ - ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1); call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 1, args, 0, NULL TSRMLS_CC); + Z_ISUNDEF(us->object)? NULL : &us->object, + &func_name, + &retval, + 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) { - ret = !Z_LVAL_P(retval); + if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) { + ret = (Z_TYPE(retval) == IS_FALSE); } else if (call_result == FAILURE) { if (value == 0) { /* lock support test (TODO: more check) */ @@ -1022,15 +966,19 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value } } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); + zval_ptr_dtor(&args[0]); break; case PHP_STREAM_OPTION_TRUNCATE_API: - ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1); switch (value) { case PHP_STREAM_TRUNCATE_SUPPORTED: - if (zend_is_callable_ex(&func_name, us->object, IS_CALLABLE_CHECK_SILENT, - NULL, NULL, NULL, NULL TSRMLS_CC)) + if (zend_is_callable_ex(&func_name, + Z_ISUNDEF(us->object)? NULL : Z_OBJ(us->object), + IS_CALLABLE_CHECK_SILENT, NULL, NULL, NULL TSRMLS_CC)) ret = PHP_STREAM_OPTION_RETURN_OK; else ret = PHP_STREAM_OPTION_RETURN_ERR; @@ -1039,18 +987,16 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value case PHP_STREAM_TRUNCATE_SET_SIZE: { ptrdiff_t new_size = *(ptrdiff_t*) ptrparam; if (new_size >= 0 && new_size <= (ptrdiff_t)LONG_MAX) { - MAKE_STD_ZVAL(zvalue); - ZVAL_LONG(zvalue, (long)new_size); - args[0] = &zvalue; + ZVAL_LONG(&args[0], (zend_long)new_size); call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL) { - if (Z_TYPE_P(retval) == IS_BOOL) { - ret = Z_LVAL_P(retval) ? PHP_STREAM_OPTION_RETURN_OK : - PHP_STREAM_OPTION_RETURN_ERR; + Z_ISUNDEF(us->object)? NULL : &us->object, + &func_name, + &retval, + 1, args, 0, NULL TSRMLS_CC); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) { + ret = (Z_TYPE(retval) == IS_TRUE) ? PHP_STREAM_OPTION_RETURN_OK : + PHP_STREAM_OPTION_RETURN_ERR; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TRUNCATE " did not return a boolean!", @@ -1061,58 +1007,53 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value "%s::" USERSTREAM_TRUNCATE " is not implemented!", us->wrapper->classname); } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&args[0]); } else { /* bad new size */ ret = PHP_STREAM_OPTION_RETURN_ERR; } break; } } + zval_ptr_dtor(&func_name); break; case PHP_STREAM_OPTION_READ_BUFFER: case PHP_STREAM_OPTION_WRITE_BUFFER: case PHP_STREAM_OPTION_READ_TIMEOUT: case PHP_STREAM_OPTION_BLOCKING: { - zval *zoption = NULL; - zval *zptrparam = NULL; - - ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1, 0); - - ALLOC_INIT_ZVAL(zoption); - ZVAL_LONG(zoption, option); - ALLOC_INIT_ZVAL(zvalue); - ALLOC_INIT_ZVAL(zptrparam); + ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1); - args[0] = &zoption; - args[1] = &zvalue; - args[2] = &zptrparam; + ZVAL_LONG(&args[0], option); + ZVAL_NULL(&args[1]); + ZVAL_NULL(&args[2]); switch(option) { case PHP_STREAM_OPTION_READ_BUFFER: case PHP_STREAM_OPTION_WRITE_BUFFER: - ZVAL_LONG(zvalue, value); + ZVAL_LONG(&args[1], value); if (ptrparam) { - ZVAL_LONG(zptrparam, *(long *)ptrparam); + ZVAL_LONG(&args[2], *(long *)ptrparam); } else { - ZVAL_LONG(zptrparam, BUFSIZ); + ZVAL_LONG(&args[2], BUFSIZ); } break; case PHP_STREAM_OPTION_READ_TIMEOUT: { struct timeval tv = *(struct timeval*)ptrparam; - ZVAL_LONG(zvalue, tv.tv_sec); - ZVAL_LONG(zptrparam, tv.tv_usec); + ZVAL_LONG(&args[1], tv.tv_sec); + ZVAL_LONG(&args[2], tv.tv_usec); break; } case PHP_STREAM_OPTION_BLOCKING: - ZVAL_LONG(zvalue, value); + ZVAL_LONG(&args[1], value); break; default: break; } call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 3, args, 0, NULL TSRMLS_CC); @@ -1121,33 +1062,22 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!", us->wrapper->classname); ret = PHP_STREAM_OPTION_RETURN_ERR; - } else if (retval && zend_is_true(retval)) { + } else if (Z_TYPE(retval) != IS_UNDEF && zend_is_true(&retval TSRMLS_CC)) { ret = PHP_STREAM_OPTION_RETURN_OK; } else { ret = PHP_STREAM_OPTION_RETURN_ERR; } - if (zoption) { - zval_ptr_dtor(&zoption); - } - if (zptrparam) { - zval_ptr_dtor(&zptrparam); - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&func_name); break; } } - /* clean up */ - if (retval) { - zval_ptr_dtor(&retval); - } - - - if (zvalue) { - zval_ptr_dtor(&zvalue); - } - return ret; } @@ -1155,46 +1085,42 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value 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; - zval **args[1]; + zval zfuncname, zretval; + zval args[1]; int call_result; - zval *object; + zval object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object TSRMLS_CC); + if (Z_TYPE(object) == IS_UNDEF) { return ret; } /* call the unlink method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; + ZVAL_STRING(&args[0], url); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_UNLINK, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_UNLINK); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname); } /* clean up */ zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); + + zval_ptr_dtor(&args[0]); return ret; } @@ -1203,51 +1129,44 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from 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; - zval **args[2]; + zval zfuncname, zretval; + zval args[2]; int call_result; - zval *object; + zval object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object TSRMLS_CC); + if (Z_TYPE(object) == IS_UNDEF) { return ret; } /* call the rename method */ - MAKE_STD_ZVAL(zold_name); - ZVAL_STRING(zold_name, url_from, 1); - args[0] = &zold_name; + ZVAL_STRING(&args[0], url_from); + ZVAL_STRING(&args[1], url_to); - MAKE_STD_ZVAL(znew_name); - ZVAL_STRING(znew_name, url_to, 1); - args[1] = &znew_name; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RENAME, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_RENAME); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", uwrap->classname); } /* clean up */ zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zold_name); - zval_ptr_dtor(&znew_name); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; } @@ -1256,57 +1175,46 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int 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; - zval **args[3]; + zval zfuncname, zretval; + zval args[3]; int call_result; - zval *object; + zval object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object TSRMLS_CC); + if (Z_TYPE(object) == IS_UNDEF) { return ret; } /* call the mkdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zmode); - ZVAL_LONG(zmode, mode); - args[1] = &zmode; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[2] = &zoptions; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], mode); + ZVAL_LONG(&args[2], options); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_MKDIR, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_MKDIR); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 3, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", uwrap->classname); } /* clean up */ zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zmode); - zval_ptr_dtor(&zoptions); + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; } @@ -1315,52 +1223,44 @@ 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; - zval **args[3]; + zval zfuncname, zretval; + zval args[2]; int call_result; - zval *object; + zval object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object TSRMLS_CC); + if (Z_TYPE(object) == IS_UNDEF) { return ret; } /* call the rmdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], options); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RMDIR, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_RMDIR); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", uwrap->classname); } /* clean up */ zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zoptions); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; } @@ -1369,81 +1269,70 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i 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; - zval **args[3]; + zval zfuncname, zretval; + zval args[3]; int call_result; - zval *object; + zval object; int ret = 0; - MAKE_STD_ZVAL(zvalue); switch(option) { case PHP_STREAM_META_TOUCH: - array_init(zvalue); + array_init(&args[2]); if(value) { struct utimbuf *newtime = (struct utimbuf *)value; - add_index_long(zvalue, 0, newtime->modtime); - add_index_long(zvalue, 1, newtime->actime); + add_index_long(&args[2], 0, newtime->modtime); + add_index_long(&args[2], 1, newtime->actime); } break; case PHP_STREAM_META_GROUP: case PHP_STREAM_META_OWNER: case PHP_STREAM_META_ACCESS: - ZVAL_LONG(zvalue, *(long *)value); + ZVAL_LONG(&args[2], *(long *)value); break; case PHP_STREAM_META_GROUP_NAME: case PHP_STREAM_META_OWNER_NAME: - ZVAL_STRING(zvalue, value, 1); + ZVAL_STRING(&args[2], value); break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option %d for " USERSTREAM_METADATA, option); - zval_ptr_dtor(&zvalue); + zval_ptr_dtor(&args[2]); return ret; } /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { - zval_ptr_dtor(&zvalue); + user_stream_create_object(uwrap, context, &object TSRMLS_CC); + if (Z_TYPE(object) == IS_UNDEF) { + zval_ptr_dtor(&args[2]); return ret; } /* call the mkdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zoption); - ZVAL_LONG(zoption, option); - args[1] = &zoption; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], option); - args[2] = &zvalue; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_METADATA, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_METADATA); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 3, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = Z_TYPE(zretval) == IS_TRUE; } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_METADATA " is not implemented!", uwrap->classname); } /* clean up */ zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zoption); - zval_ptr_dtor(&zvalue); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[2]); return ret; } @@ -1453,40 +1342,34 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i 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; - zval **args[2]; + zval zfuncname, zretval; + zval args[2]; int call_result; - zval *object; + zval object; int ret = -1; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object TSRMLS_CC); + if (Z_TYPE(object) == IS_UNDEF) { return ret; } /* call it's stat_url method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zflags); - ZVAL_LONG(zflags, flags); - args[1] = &zflags; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], flags); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_STATURL, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_STATURL); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval != NULL && Z_TYPE_P(zretval) == IS_ARRAY) { + if (call_result == SUCCESS && Z_TYPE(zretval) == IS_ARRAY) { /* We got the info we needed */ - if (SUCCESS == statbuf_from_array(zretval, ssb TSRMLS_CC)) + if (SUCCESS == statbuf_from_array(&zretval, ssb TSRMLS_CC)) ret = 0; } else { if (call_result == FAILURE) { @@ -1497,12 +1380,11 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i /* clean up */ zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zflags); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; @@ -1511,7 +1393,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; size_t didread = 0; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; @@ -1521,18 +1403,18 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou if (count != sizeof(php_stream_dirent)) return 0; - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) != IS_BOOL) { - convert_to_string(retval); - PHP_STRLCPY(ent->d_name, Z_STRVAL_P(retval), sizeof(ent->d_name), Z_STRLEN_P(retval)); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) { + convert_to_string(&retval); + PHP_STRLCPY(ent->d_name, Z_STRVAL(retval), sizeof(ent->d_name), Z_STRLEN(retval)); didread = sizeof(php_stream_dirent); } else if (call_result == FAILURE) { @@ -1540,8 +1422,8 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou us->wrapper->classname); } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return didread; } @@ -1549,45 +1431,45 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1); call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (retval) - zval_ptr_dtor(&retval); - + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&us->object); efree(us); return 0; } -static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_userstreamop_rewinddir(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1); call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return 0; @@ -1597,28 +1479,25 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T { php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; zval func_name; - zval *retval = NULL; - zval *zcastas = NULL; - zval **args[1]; + zval retval; + zval args[1]; php_stream * intstream = NULL; int call_result; int ret = FAILURE; - ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1); - ALLOC_INIT_ZVAL(zcastas); switch(castas) { case PHP_STREAM_AS_FD_FOR_SELECT: - ZVAL_LONG(zcastas, PHP_STREAM_AS_FD_FOR_SELECT); + ZVAL_LONG(&args[0], PHP_STREAM_AS_FD_FOR_SELECT); break; default: - ZVAL_LONG(zcastas, PHP_STREAM_AS_STDIO); + ZVAL_LONG(&args[0], PHP_STREAM_AS_STDIO); break; } - args[0] = &zcastas; call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); @@ -1629,7 +1508,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T us->wrapper->classname); break; } - if (retval == NULL || !zend_is_true(retval)) { + if (Z_ISUNDEF(retval) || !zend_is_true(&retval TSRMLS_CC)) { break; } php_stream_from_zval_no_verify(intstream, &retval); @@ -1647,12 +1526,9 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T ret = php_stream_cast(intstream, castas, retptr, 1); } while (0); - if (retval) { - zval_ptr_dtor(&retval); - } - if (zcastas) { - zval_ptr_dtor(&zcastas); - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); + zval_ptr_dtor(&args[0]); return ret; } diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index a6dc115962..7427a794b4 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -39,6 +39,13 @@ # define MSG_PEEK 0 #endif +#ifdef PHP_WIN32 +/* send/recv family on windows expects int */ +# define XP_SOCK_BUF_SIZE(sz) (((sz) > INT_MAX) ? INT_MAX : (int)(sz)) +#else +# define XP_SOCK_BUF_SIZE(sz) (sz) +#endif + php_stream_ops php_stream_generic_socket_ops; PHPAPI php_stream_ops php_stream_socket_ops; php_stream_ops php_stream_udp_socket_ops; @@ -57,7 +64,7 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count int didwrite; struct timeval *ptimeout; - if (sock->socket == -1) { + if (!sock || sock->socket == -1) { return 0; } @@ -67,7 +74,7 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count ptimeout = &sock->timeout; retry: - didwrite = send(sock->socket, buf, count, (sock->is_blocked && ptimeout) ? MSG_DONTWAIT : 0); + didwrite = send(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && ptimeout) ? MSG_DONTWAIT : 0); if (didwrite <= 0) { long err = php_socket_errno(); @@ -95,13 +102,13 @@ retry: } while (err == EINTR); } estr = php_socket_strerror(err, NULL, 0); - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "send of %ld bytes failed with errno=%ld %s", - (long)count, err, estr); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "send of " ZEND_LONG_FMT " bytes failed with errno=%ld %s", + (zend_long)count, err, estr); efree(estr); } if (didwrite > 0) { - php_stream_notify_progress_increment(stream->context, didwrite, 0); + php_stream_notify_progress_increment(PHP_STREAM_CONTEXT(stream), didwrite, 0); } if (didwrite < 0) { @@ -116,7 +123,7 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data int retval; struct timeval *ptimeout; - if (sock->socket == -1) { + if (!sock || sock->socket == -1) { return; } @@ -144,9 +151,9 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - int nr_bytes = 0; + ssize_t nr_bytes = 0; - if (sock->socket == -1) { + if (!sock || sock->socket == -1) { return 0; } @@ -156,12 +163,12 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS return 0; } - nr_bytes = recv(sock->socket, buf, count, (sock->is_blocked && sock->timeout.tv_sec != -1) ? MSG_DONTWAIT : 0); + nr_bytes = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && sock->timeout.tv_sec != -1) ? MSG_DONTWAIT : 0); stream->eof = (nr_bytes == 0 || (nr_bytes == -1 && php_socket_errno() != EWOULDBLOCK)); if (nr_bytes > 0) { - php_stream_notify_progress_increment(stream->context, nr_bytes, 0); + php_stream_notify_progress_increment(PHP_STREAM_CONTEXT(stream), nr_bytes, 0); } if (nr_bytes < 0) { @@ -179,6 +186,10 @@ static int php_sockop_close(php_stream *stream, int close_handle TSRMLS_DC) int n; #endif + if (!sock) { + return 0; + } + if (close_handle) { #ifdef PHP_WIN32 @@ -222,11 +233,12 @@ static int php_sockop_flush(php_stream *stream TSRMLS_DC) static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) { - php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; #if ZEND_WIN32 return 0; #else - return fstat(sock->socket, &ssb->sb); + php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; + + return zend_fstat(sock->socket, &ssb->sb); #endif } @@ -236,14 +248,19 @@ static inline int sock_sendto(php_netstream_data_t *sock, const char *buf, size_ { int ret; if (addr) { - ret = sendto(sock->socket, buf, buflen, flags, addr, addrlen); + ret = sendto(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, addr, XP_SOCK_BUF_SIZE(addrlen)); + return (ret == SOCK_CONN_ERR) ? -1 : ret; } +#ifdef PHP_WIN32 + return ((ret = send(sock->socket, buf, buflen > INT_MAX ? INT_MAX : (int)buflen, flags)) == SOCK_CONN_ERR) ? -1 : ret; +#else return ((ret = send(sock->socket, buf, buflen, flags)) == SOCK_CONN_ERR) ? -1 : ret; +#endif } static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t buflen, int flags, - char **textaddr, long *textaddrlen, + zend_string **textaddr, struct sockaddr **addr, socklen_t *addrlen TSRMLS_DC) { @@ -253,12 +270,12 @@ static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t bu int want_addr = textaddr || addr; if (want_addr) { - ret = recvfrom(sock->socket, buf, buflen, flags, (struct sockaddr*)&sa, &sl); + ret = recvfrom(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, (struct sockaddr*)&sa, &sl); ret = (ret == SOCK_CONN_ERR) ? -1 : ret; php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, addr, addrlen TSRMLS_CC); + textaddr, addr, addrlen TSRMLS_CC); } else { - ret = recv(sock->socket, buf, buflen, flags); + ret = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags); ret = (ret == SOCK_CONN_ERR) ? -1 : ret; } @@ -271,6 +288,10 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; php_stream_xport_param *xparam; + if (!sock) { + return PHP_STREAM_OPTION_RETURN_NOTIMPL; + } + switch(option) { case PHP_STREAM_OPTION_CHECK_LIVENESS: { @@ -330,7 +351,6 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void case STREAM_XPORT_OP_GET_NAME: xparam->outputs.returncode = php_network_get_sock_name(sock->socket, xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, xparam->want_addr ? &xparam->outputs.addr : NULL, xparam->want_addr ? &xparam->outputs.addrlen : NULL TSRMLS_CC); @@ -339,7 +359,6 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void case STREAM_XPORT_OP_GET_PEER_NAME: xparam->outputs.returncode = php_network_get_peer_name(sock->socket, xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, xparam->want_addr ? &xparam->outputs.addr : NULL, xparam->want_addr ? &xparam->outputs.addrlen : NULL TSRMLS_CC); @@ -375,7 +394,6 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void xparam->inputs.buf, xparam->inputs.buflen, flags, xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, xparam->want_addr ? &xparam->outputs.addr : NULL, xparam->want_addr ? &xparam->outputs.addrlen : NULL TSRMLS_CC); @@ -413,6 +431,10 @@ static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) { php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; + if (!sock) { + return FAILURE; + } + switch(castas) { case PHP_STREAM_AS_STDIO: if (ret) { @@ -521,7 +543,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, size_t 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, zend_string **err TSRMLS_DC) { char *colon; char *host = NULL; @@ -534,7 +556,7 @@ static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *po p = memchr(str + 1, ']', str_len - 2); if (!p || *(p + 1) != ':') { if (get_err) { - spprintf(err, 0, "Failed to parse IPv6 address \"%s\"", str); + *err = strpprintf(0, "Failed to parse IPv6 address \"%s\"", str); } return NULL; } @@ -552,7 +574,7 @@ static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *po host = estrndup(str, colon - str); } else { if (get_err) { - spprintf(err, 0, "Failed to parse address \"%s\"", str); + *err = strpprintf(0, "Failed to parse address \"%s\"", str); } return NULL; } @@ -570,6 +592,8 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t * { char *host = NULL; int portno, err; + long sockopts = STREAM_SOCKOP_NONE; + zval *tmpzval = NULL; #ifdef AF_UNIX if (stream->ops == &php_stream_unix_socket_ops || stream->ops == &php_stream_unixdg_socket_ops) { @@ -579,7 +603,7 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t * if (sock->socket == SOCK_ERR) { if (xparam->want_errortext) { - spprintf(&xparam->outputs.error_text, 0, "Failed to create unix%s socket %s", + xparam->outputs.error_text = strpprintf(0, "Failed to create unix%s socket %s", stream->ops == &php_stream_unix_socket_ops ? "" : "datagram", strerror(errno)); } @@ -599,8 +623,28 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t * return -1; } +#ifdef SO_REUSEPORT + if (PHP_STREAM_CONTEXT(stream) + && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_reuseport")) != NULL + && zend_is_true(tmpzval TSRMLS_CC) + ) { + sockopts |= STREAM_SOCKOP_SO_REUSEPORT; + } +#endif + +#ifdef SO_BROADCAST + if (stream->ops == &php_stream_udp_socket_ops /* SO_BROADCAST is only applicable for UDP */ + && PHP_STREAM_CONTEXT(stream) + && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_broadcast")) != NULL + && zend_is_true(tmpzval TSRMLS_CC) + ) { + sockopts |= STREAM_SOCKOP_SO_BROADCAST; + } +#endif + sock->socket = php_network_bind_socket_to_local_addr(host, portno, stream->ops == &php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM, + sockopts, xparam->want_errortext ? &xparam->outputs.error_text : NULL, &err TSRMLS_CC); @@ -619,7 +663,8 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ int portno, bindport = 0; int err = 0; int ret; - zval **tmpzval = NULL; + zval *tmpzval = NULL; + long sockopts = STREAM_SOCKOP_NONE; #ifdef AF_UNIX if (stream->ops == &php_stream_unix_socket_ops || stream->ops == &php_stream_unixdg_socket_ops) { @@ -629,7 +674,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ if (sock->socket == SOCK_ERR) { if (xparam->want_errortext) { - spprintf(&xparam->outputs.error_text, 0, "Failed to create unix socket"); + xparam->outputs.error_text = strpprintf(0, "Failed to create unix socket"); } return -1; } @@ -654,17 +699,27 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ return -1; } - if (stream->context && php_stream_context_get_option(stream->context, "socket", "bindto", &tmpzval) == SUCCESS) { - if (Z_TYPE_PP(tmpzval) != IS_STRING) { + if (PHP_STREAM_CONTEXT(stream) && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "bindto")) != NULL) { + if (Z_TYPE_P(tmpzval) != IS_STRING) { if (xparam->want_errortext) { - spprintf(&xparam->outputs.error_text, 0, "local_addr context option is not a string."); + xparam->outputs.error_text = strpprintf(0, "local_addr context option is not a string."); } efree(host); return -1; } - bindto = parse_ip_address_ex(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC); + bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC); } +#ifdef SO_BROADCAST + if (stream->ops == &php_stream_udp_socket_ops /* SO_BROADCAST is only applicable for UDP */ + && PHP_STREAM_CONTEXT(stream) + && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_broadcast")) != NULL + && zend_is_true(tmpzval TSRMLS_CC) + ) { + sockopts |= STREAM_SOCKOP_SO_BROADCAST; + } +#endif + /* Note: the test here for php_stream_udp_socket_ops is important, because we * want the default to be TCP sockets so that the openssl extension can * re-use this code. */ @@ -676,7 +731,8 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ xparam->want_errortext ? &xparam->outputs.error_text : NULL, &err, bindto, - bindport + bindport, + sockopts TSRMLS_CC); ret = sock->socket == -1 ? -1 : 0; @@ -710,7 +766,6 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t clisock = php_network_accept_incoming(sock->socket, xparam->want_textaddr ? &xparam->outputs.textaddr : NULL, - xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL, xparam->want_addr ? &xparam->outputs.addr : NULL, xparam->want_addr ? &xparam->outputs.addrlen : NULL, xparam->inputs.timeout, @@ -732,9 +787,9 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+"); if (xparam->outputs.client) { - xparam->outputs.client->context = stream->context; - if (stream->context) { - zend_list_addref(stream->context->rsrc_id); + xparam->outputs.client->ctx = stream->ctx; + if (stream->ctx) { + GC_REFCOUNT(stream->ctx)++; } } } diff --git a/main/strlcat.c b/main/strlcat.c index b7aa06e8a2..65811e90c2 100644 --- a/main/strlcat.c +++ b/main/strlcat.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/strlcpy.c b/main/strlcpy.c index 7738238bd5..737036c4a1 100644 --- a/main/strlcpy.c +++ b/main/strlcpy.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/win32_internal_function_disabled.h b/main/win32_internal_function_disabled.h index 7365262772..a412305ea3 100644 --- a/main/win32_internal_function_disabled.h +++ b/main/win32_internal_function_disabled.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ diff --git a/main/win95nt.h b/main/win95nt.h index ce2b002f38..febffecadf 100644 --- a/main/win95nt.h +++ b/main/win95nt.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -55,7 +55,7 @@ typedef char * caddr_t; typedef unsigned int uint; typedef unsigned long ulong; #if !NSAPI -typedef long pid_t; +typedef int pid_t; #endif /* missing in vc5 math.h */ |
