diff options
Diffstat (limited to 'main/rfc1867.c')
-rw-r--r-- | main/rfc1867.c | 293 |
1 files changed, 155 insertions, 138 deletions
diff --git a/main/rfc1867.c b/main/rfc1867.c index ca8f28b553..1db3cd303f 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -33,7 +33,7 @@ #include "php_variables.h" #include "rfc1867.h" #include "ext/standard/php_string.h" -#include "ext/standard/php_smart_str.h" +#include "ext/standard/php_smart_string.h" #if defined(PHP_WIN32) && !defined(HAVE_ATOLL) # define atoll(s) _atoi64(s) @@ -42,13 +42,13 @@ #define DEBUG_FILE_UPLOAD ZEND_DEBUG -static int dummy_encoding_translation(TSRMLS_D) +static int dummy_encoding_translation(void) { return 0; } -static char *php_ap_getword(const zend_encoding *encoding, char **line, char stop TSRMLS_DC); -static char *php_ap_getword_conf(const zend_encoding *encoding, char *str TSRMLS_DC); +static char *php_ap_getword(const zend_encoding *encoding, char **line, char stop); +static char *php_ap_getword_conf(const zend_encoding *encoding, char *str); static php_rfc1867_encoding_translation_t php_rfc1867_encoding_translation = dummy_encoding_translation; static php_rfc1867_get_detect_order_t php_rfc1867_get_detect_order = NULL; @@ -57,9 +57,9 @@ static php_rfc1867_getword_t php_rfc1867_getword = php_ap_getword; static php_rfc1867_getword_conf_t php_rfc1867_getword_conf = php_ap_getword_conf; 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; +PHPAPI int (*php_rfc1867_callback)(unsigned int event, void *event_data, void **extra) = 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); /* The longest property name we use in an uploaded file array */ #define MAX_SIZE_OF_INDEX sizeof("[tmp_name]") @@ -77,7 +77,7 @@ static void safe_php_register_variable(char *var, char *strval, int val_len, zva #define UPLOAD_ERROR_F 7 /* Failed to write file to disk */ #define UPLOAD_ERROR_X 8 /* File upload stopped by extension */ -void php_rfc1867_register_constants(TSRMLS_D) /* {{{ */ +void php_rfc1867_register_constants(void) /* {{{ */ { REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_OK", UPLOAD_ERROR_OK, CONST_CS | CONST_PERSISTENT); REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_INI_SIZE", UPLOAD_ERROR_A, CONST_CS | CONST_PERSISTENT); @@ -90,7 +90,7 @@ void php_rfc1867_register_constants(TSRMLS_D) /* {{{ */ } /* }}} */ -static void normalize_protected_variable(char *varname TSRMLS_DC) /* {{{ */ +static void normalize_protected_variable(char *varname) /* {{{ */ { char *s = varname, *index = NULL, *indexend = NULL, *p; @@ -148,60 +148,65 @@ static void normalize_protected_variable(char *varname TSRMLS_DC) /* {{{ */ } /* }}} */ -static void add_protected_variable(char *varname TSRMLS_DC) /* {{{ */ +static void add_protected_variable(char *varname) /* {{{ */ { - int dummy = 1; - - normalize_protected_variable(varname TSRMLS_CC); - zend_hash_add(&PG(rfc1867_protected_variables), varname, strlen(varname)+1, &dummy, sizeof(int), NULL); + normalize_protected_variable(varname); + zend_hash_str_add_empty_element(&PG(rfc1867_protected_variables), varname, strlen(varname)); } /* }}} */ -static zend_bool is_protected_variable(char *varname TSRMLS_DC) /* {{{ */ +static zend_bool is_protected_variable(char *varname) /* {{{ */ { - normalize_protected_variable(varname TSRMLS_CC); - return zend_hash_exists(&PG(rfc1867_protected_variables), varname, strlen(varname)+1); + normalize_protected_variable(varname); + 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) /* {{{ */ { - if (override_protection || !is_protected_variable(var TSRMLS_CC)) { - php_register_variable_safe(var, strval, val_len, track_vars_array TSRMLS_CC); + if (override_protection || !is_protected_variable(var)) { + php_register_variable_safe(var, strval, val_len, track_vars_array); } } /* }}} */ -static void safe_php_register_variable_ex(char *var, zval *val, zval *track_vars_array, zend_bool override_protection TSRMLS_DC) /* {{{ */ +static void safe_php_register_variable_ex(char *var, zval *val, zval *track_vars_array, zend_bool override_protection) /* {{{ */ { - if (override_protection || !is_protected_variable(var TSRMLS_CC)) { - php_register_variable_ex(var, val, track_vars_array TSRMLS_CC); + if (override_protection || !is_protected_variable(var)) { + php_register_variable_ex(var, val, track_vars_array); } } /* }}} */ -static void register_http_post_files_variable(char *strvar, char *val, zval *http_post_files, zend_bool override_protection TSRMLS_DC) /* {{{ */ +static void register_http_post_files_variable(char *strvar, char *val, zval *http_post_files, zend_bool override_protection) /* {{{ */ { - safe_php_register_variable(strvar, val, strlen(val), http_post_files, override_protection TSRMLS_CC); + safe_php_register_variable(strvar, val, strlen(val), http_post_files, override_protection); } /* }}} */ -static void register_http_post_files_variable_ex(char *var, zval *val, zval *http_post_files, zend_bool override_protection TSRMLS_DC) /* {{{ */ +static void register_http_post_files_variable_ex(char *var, zval *val, zval *http_post_files, zend_bool override_protection) /* {{{ */ { - safe_php_register_variable_ex(var, val, http_post_files, override_protection TSRMLS_CC); + safe_php_register_variable_ex(var, val, http_post_files, override_protection); } /* }}} */ -static int unlink_filename(char **filename TSRMLS_DC) /* {{{ */ +static int unlink_filename(zval *el) /* {{{ */ { - VCWD_UNLINK(*filename); + zend_string *filename = Z_STR_P(el); + VCWD_UNLINK(ZSTR_VAL(filename)); return 0; } /* }}} */ -void destroy_uploaded_files_hash(TSRMLS_D) /* {{{ */ + +static void free_filename(zval *el) { + zend_string *filename = Z_STR_P(el); + zend_string_release(filename); +} + +PHPAPI void destroy_uploaded_files_hash(void) /* {{{ */ { - zend_hash_apply(SG(rfc1867_uploaded_files), (apply_func_t) unlink_filename TSRMLS_CC); + zend_hash_apply(SG(rfc1867_uploaded_files), unlink_filename); zend_hash_destroy(SG(rfc1867_uploaded_files)); FREE_HASHTABLE(SG(rfc1867_uploaded_files)); } @@ -238,7 +243,7 @@ typedef struct { * Fill up the buffer with client data. * Returns number of bytes added to buffer. */ -static int fill_buffer(multipart_buffer *self TSRMLS_DC) +static int fill_buffer(multipart_buffer *self) { int bytes_to_read, total_read = 0, actual_read = 0; @@ -257,7 +262,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); /* update the buffer length */ if (actual_read > 0) { @@ -274,9 +279,9 @@ static int fill_buffer(multipart_buffer *self TSRMLS_DC) } /* eof if we are out of bytes, or if we hit the final boundary */ -static int multipart_buffer_eof(multipart_buffer *self TSRMLS_DC) +static int multipart_buffer_eof(multipart_buffer *self) { - if ( (self->bytes_in_buffer == 0 && fill_buffer(self TSRMLS_CC) < 1) ) { + if ( (self->bytes_in_buffer == 0 && fill_buffer(self) < 1) ) { return 1; } else { return 0; @@ -284,7 +289,7 @@ static int multipart_buffer_eof(multipart_buffer *self TSRMLS_DC) } /* create new multipart_buffer structure */ -static multipart_buffer *multipart_buffer_new(char *boundary, int boundary_len TSRMLS_DC) +static multipart_buffer *multipart_buffer_new(char *boundary, int boundary_len) { multipart_buffer *self = (multipart_buffer *) ecalloc(1, sizeof(multipart_buffer)); @@ -296,13 +301,13 @@ 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; - if (php_rfc1867_encoding_translation(TSRMLS_C)) { - php_rfc1867_get_detect_order(&self->detect_order, &self->detect_order_size TSRMLS_CC); + if (php_rfc1867_encoding_translation()) { + php_rfc1867_get_detect_order(&self->detect_order, &self->detect_order_size); } else { self->detect_order = NULL; self->detect_order_size = 0; @@ -359,12 +364,12 @@ static char *next_line(multipart_buffer *self) } /* Returns the next CRLF terminated line from the client */ -static char *get_line(multipart_buffer *self TSRMLS_DC) +static char *get_line(multipart_buffer *self) { char* ptr = next_line(self); if (!ptr) { - fill_buffer(self TSRMLS_CC); + fill_buffer(self); ptr = next_line(self); } @@ -383,12 +388,12 @@ static void php_free_hdr_entry(mime_header_entry *h) } /* finds a boundary */ -static int find_boundary(multipart_buffer *self, char *boundary TSRMLS_DC) +static int find_boundary(multipart_buffer *self, char *boundary) { char *line; /* loop thru lines */ - while( (line = get_line(self TSRMLS_CC)) ) + while( (line = get_line(self)) ) { /* finished if we found the boundary */ if (!strcmp(line, boundary)) { @@ -401,27 +406,26 @@ static int find_boundary(multipart_buffer *self, char *boundary TSRMLS_DC) } /* parse headers */ -static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC) +static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header) { char *line; mime_header_entry entry = {0}; - smart_str buf_value = {0}; + smart_string buf_value = {0}; char *key = NULL; /* didn't find boundary, abort */ - if (!find_boundary(self, self->boundary TSRMLS_CC)) { + if (!find_boundary(self, self->boundary)) { return 0; } /* get lines of text, or CRLF_CRLF */ - while( (line = get_line(self TSRMLS_CC)) && line[0] != '\0' ) - { + while ((line = get_line(self)) && line[0] != '\0') { /* add header to table */ char *value = NULL; - if (php_rfc1867_encoding_translation(TSRMLS_C)) { - self->input_encoding = zend_multibyte_encoding_detector((unsigned char *)line, strlen(line), self->detect_order, self->detect_order_size TSRMLS_CC); + if (php_rfc1867_encoding_translation()) { + self->input_encoding = zend_multibyte_encoding_detector((const unsigned char *) line, strlen(line), self->detect_order, self->detect_order_size); } /* space in the beginning means same header */ @@ -430,9 +434,9 @@ static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header T } if (value) { - if(buf_value.c && key) { + if (buf_value.c && key) { /* new entry, add the old one to the list */ - smart_str_0(&buf_value); + smart_string_0(&buf_value); entry.key = key; entry.value = buf_value.c; zend_llist_add_element(header, &entry); @@ -441,19 +445,20 @@ static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header T } *value = '\0'; - do { value++; } while(isspace(*value)); + do { value++; } while (isspace(*value)); key = estrdup(line); - smart_str_appends(&buf_value, value); + smart_string_appends(&buf_value, value); } else if (buf_value.c) { /* If no ':' on the line, add to previous line */ - smart_str_appends(&buf_value, line); + smart_string_appends(&buf_value, line); } else { continue; } } - if(buf_value.c && key) { + + if (buf_value.c && key) { /* add the last one to the list */ - smart_str_0(&buf_value); + smart_string_0(&buf_value); entry.key = key; entry.value = buf_value.c; zend_llist_add_element(header, &entry); @@ -481,7 +486,7 @@ static char *php_mime_get_hdr_value(zend_llist header, char *key) return NULL; } -static char *php_ap_getword(const zend_encoding *encoding, char **line, char stop TSRMLS_DC) +static char *php_ap_getword(const zend_encoding *encoding, char **line, char stop) { char *pos = *line, quote; char *res; @@ -535,7 +540,7 @@ static char *substring_conf(char *start, int len, char quote) return result; } -static char *php_ap_getword_conf(const zend_encoding *encoding, char *str TSRMLS_DC) +static char *php_ap_getword_conf(const zend_encoding *encoding, char *str) { while (*str && isspace(*str)) { ++str; @@ -549,7 +554,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; @@ -560,7 +565,7 @@ static char *php_ap_getword_conf(const zend_encoding *encoding, char *str TSRMLS } } -static char *php_ap_basename(const zend_encoding *encoding, char *path TSRMLS_DC) +static char *php_ap_basename(const zend_encoding *encoding, char *path) { char *s = strrchr(path, '\\'); char *s2 = strrchr(path, '/'); @@ -609,14 +614,14 @@ 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) { - int len, max; + size_t len, max; char *bound; /* fill buffer if needed */ if (bytes > self->bytes_in_buffer) { - fill_buffer(self TSRMLS_CC); + fill_buffer(self); } /* look for a potential boundary match, only read data up to that point */ @@ -644,23 +649,23 @@ 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) { char buf[FILLUNIT], *out=NULL; int total_bytes=0, read_bytes=0; - while((read_bytes = multipart_buffer_read(self, buf, sizeof(buf), NULL TSRMLS_CC))) { + while((read_bytes = multipart_buffer_read(self, buf, sizeof(buf), NULL))) { out = erealloc(out, total_bytes + read_bytes + 1); memcpy(out + total_bytes, buf, read_bytes); total_bytes += read_bytes; @@ -683,11 +688,11 @@ static char *multipart_buffer_read_body(multipart_buffer *self, unsigned int *le SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ { char *boundary, *s = NULL, *boundary_end = NULL, *start_arr = NULL, *array_index = NULL; - char *temp_filename = NULL, *lbuf = NULL, *abuf = NULL; + char *lbuf = NULL, *abuf = NULL; + zend_string *temp_filename = NULL; 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; @@ -696,13 +701,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ void *event_extra_data = NULL; unsigned int llen = 0; int upload_cnt = INI_INT("max_file_uploads"); - const zend_encoding *internal_encoding = zend_multibyte_get_internal_encoding(TSRMLS_C); + const zend_encoding *internal_encoding = zend_multibyte_get_internal_encoding(); 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) { + if (php_rfc1867_encoding_translation() && internal_encoding) { getword = php_rfc1867_getword; getword_conf = php_rfc1867_getword_conf; _basename = php_rfc1867_basename; @@ -713,14 +718,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); @@ -737,7 +742,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } boundary++; - boundary_len = strlen(boundary); + boundary_len = (int)strlen(boundary); if (boundary[0] == '"') { boundary++; @@ -756,22 +761,22 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } /* Initialize the buffer */ - if (!(mbuff = multipart_buffer_new(boundary, boundary_len TSRMLS_CC))) { + if (!(mbuff = multipart_buffer_new(boundary, boundary_len))) { sapi_module.sapi_error(E_WARNING, "Unable to initialize the input buffer"); return; } /* 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; + if (Z_TYPE(PG(http_globals)[TRACK_VARS_FILES]) != IS_ARRAY) { + /* php_auto_globals_create_files() might have already done that */ + 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); @@ -779,21 +784,21 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ multipart_event_start event_start; event_start.content_length = SG(request_info).content_length; - if (php_rfc1867_callback(MULTIPART_EVENT_START, &event_start, &event_extra_data TSRMLS_CC) == FAILURE) { + if (php_rfc1867_callback(MULTIPART_EVENT_START, &event_start, &event_extra_data) == FAILURE) { goto fileupload_done; } } - while (!multipart_buffer_eof(mbuff TSRMLS_CC)) + while (!multipart_buffer_eof(mbuff)) { 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); - if (!multipart_buffer_headers(mbuff, &header TSRMLS_CC)) { + if (!multipart_buffer_headers(mbuff, &header)) { goto fileupload_done; } @@ -805,7 +810,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ ++cd; } - while (*cd && (pair = getword(mbuff->input_encoding, &cd, ';' TSRMLS_CC))) + while (*cd && (pair = getword(mbuff->input_encoding, &cd, ';'))) { char *key = NULL, *word = pair; @@ -814,17 +819,17 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } if (strchr(pair, '=')) { - key = getword(mbuff->input_encoding, &pair, '=' TSRMLS_CC); + key = getword(mbuff->input_encoding, &pair, '='); if (!strcasecmp(key, "name")) { if (param) { efree(param); } - param = getword_conf(mbuff->input_encoding, pair TSRMLS_CC); + param = getword_conf(mbuff->input_encoding, pair); if (mbuff->input_encoding && internal_encoding) { unsigned char *new_param; size_t new_param_len; - if ((size_t)-1 != zend_multibyte_encoding_converter(&new_param, &new_param_len, (unsigned char *)param, strlen(param), internal_encoding, mbuff->input_encoding TSRMLS_CC)) { + if ((size_t)-1 != zend_multibyte_encoding_converter(&new_param, &new_param_len, (unsigned char *)param, strlen(param), internal_encoding, mbuff->input_encoding)) { efree(param); param = (char *)new_param; } @@ -833,11 +838,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ if (filename) { efree(filename); } - filename = getword_conf(mbuff->input_encoding, pair TSRMLS_CC); + filename = getword_conf(mbuff->input_encoding, pair); if (mbuff->input_encoding && internal_encoding) { unsigned char *new_filename; size_t new_filename_len; - if ((size_t)-1 != zend_multibyte_encoding_converter(&new_filename, &new_filename_len, (unsigned char *)filename, strlen(filename), internal_encoding, mbuff->input_encoding TSRMLS_CC)) { + if ((size_t)-1 != zend_multibyte_encoding_converter(&new_filename, &new_filename_len, (unsigned char *)filename, strlen(filename), internal_encoding, mbuff->input_encoding)) { efree(filename); filename = (char *)new_filename; } @@ -852,9 +857,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; - char *value = multipart_buffer_read_body(mbuff, &value_len TSRMLS_CC); - unsigned int new_val_len; /* Dummy variable */ + size_t value_len; + char *value = multipart_buffer_read_body(mbuff, &value_len); + size_t new_val_len; /* Dummy variable */ if (!value) { value = estrdup(""); @@ -864,14 +869,14 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ if (mbuff->input_encoding && internal_encoding) { unsigned char *new_value; size_t new_value_len; - if ((size_t)-1 != zend_multibyte_encoding_converter(&new_value, &new_value_len, (unsigned char *)value, value_len, internal_encoding, mbuff->input_encoding TSRMLS_CC)) { + if ((size_t)-1 != zend_multibyte_encoding_converter(&new_value, &new_value_len, (unsigned char *)value, value_len, internal_encoding, mbuff->input_encoding)) { efree(value); value = (char *)new_value; value_len = new_value_len; } } - if (++count <= PG(max_input_vars) && sapi_module.input_filter(PARSE_POST, param, &value, value_len, &new_val_len TSRMLS_CC)) { + if (++count <= PG(max_input_vars) && sapi_module.input_filter(PARSE_POST, param, &value, value_len, &new_val_len)) { if (php_rfc1867_callback != NULL) { multipart_event_formdata event_formdata; size_t newlength = new_val_len; @@ -881,17 +886,17 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ event_formdata.value = &value; event_formdata.length = new_val_len; event_formdata.newlength = &newlength; - if (php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data TSRMLS_CC) == FAILURE) { + if (php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data) == FAILURE) { efree(param); efree(value); continue; } new_val_len = newlength; } - safe_php_register_variable(param, value, new_val_len, array_ptr, 0 TSRMLS_CC); + safe_php_register_variable(param, value, new_val_len, array_ptr, 0); } 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, 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) { @@ -902,7 +907,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ event_formdata.value = &value; event_formdata.length = value_len; event_formdata.newlength = NULL; - php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data TSRMLS_CC); + php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data); } } @@ -978,8 +983,8 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ event_file_start.post_bytes_processed = SG(read_post_bytes); event_file_start.name = param; event_file_start.filename = &filename; - if (php_rfc1867_callback(MULTIPART_EVENT_FILE_START, &event_file_start, &event_extra_data TSRMLS_CC) == FAILURE) { - temp_filename = ""; + if (php_rfc1867_callback(MULTIPART_EVENT_FILE_START, &event_file_start, &event_extra_data) == FAILURE) { + temp_filename = NULL; efree(param); efree(filename); continue; @@ -1004,14 +1009,14 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ if (!cancel_upload) { /* only bother to open temp file if we have data */ - blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC); + blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end); #if DEBUG_FILE_UPLOAD if (blen > 0) { #else /* in non-debug mode we have no problem with 0-length files */ { #endif - fd = php_open_temporary_fd_ex(PG(upload_tmp_dir), "php", &temp_filename, 1 TSRMLS_CC); + fd = php_open_temporary_fd_ex(PG(upload_tmp_dir), "php", &temp_filename, 1); upload_cnt--; if (fd == -1) { sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file"); @@ -1030,24 +1035,28 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ event_file_data.data = buff; event_file_data.length = blen; event_file_data.newlength = &blen; - if (php_rfc1867_callback(MULTIPART_EVENT_FILE_DATA, &event_file_data, &event_extra_data TSRMLS_CC) == FAILURE) { + if (php_rfc1867_callback(MULTIPART_EVENT_FILE_DATA, &event_file_data, &event_extra_data) == FAILURE) { cancel_upload = UPLOAD_ERROR_X; continue; } } - 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 */ @@ -1067,7 +1076,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } /* read data for next iteration */ - blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC); + blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end); } if (fd != -1) { /* may not be initialized if file could not be created */ @@ -1090,9 +1099,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ multipart_event_file_end event_file_end; event_file_end.post_bytes_processed = SG(read_post_bytes); - event_file_end.temp_filename = temp_filename; + event_file_end.temp_filename = ZSTR_VAL(temp_filename); event_file_end.cancel_upload = cancel_upload; - if (php_rfc1867_callback(MULTIPART_EVENT_FILE_END, &event_file_end, &event_extra_data TSRMLS_CC) == FAILURE) { + if (php_rfc1867_callback(MULTIPART_EVENT_FILE_END, &event_file_end, &event_extra_data) == FAILURE) { cancel_upload = UPLOAD_ERROR_X; } } @@ -1100,13 +1109,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ if (cancel_upload) { if (temp_filename) { if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */ - unlink(temp_filename); + unlink(ZSTR_VAL(temp_filename)); } - efree(temp_filename); + zend_string_release(temp_filename); } - temp_filename = ""; + temp_filename = NULL; } else { - zend_hash_add(SG(rfc1867_uploaded_files), temp_filename, strlen(temp_filename) + 1, &temp_filename, sizeof(char *), NULL); + zend_hash_add_ptr(SG(rfc1867_uploaded_files), temp_filename, temp_filename); } /* is_arr_upload is true when name of file upload field @@ -1115,7 +1124,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); } @@ -1124,7 +1133,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; } @@ -1142,13 +1151,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ * the full path of the file on the user's filesystem, which means that unless * the user does basename() they get a bogus file name. Until IE's user base drops * to nill or problem is fixed this code must remain enabled for all systems. */ - s = _basename(internal_encoding, filename TSRMLS_CC); + s = _basename(internal_encoding, filename); if (!s) { s = filename; } if (!is_anonymous) { - safe_php_register_variable(lbuf, s, strlen(s), NULL, 0 TSRMLS_CC); + safe_php_register_variable(lbuf, s, strlen(s), NULL, 0); } /* Add $foo[name] */ @@ -1157,7 +1166,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); efree(filename); s = NULL; @@ -1179,7 +1188,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ snprintf(lbuf, llen, "%s_type", param); } if (!is_anonymous) { - safe_php_register_variable(lbuf, cd, strlen(cd), NULL, 0 TSRMLS_CC); + safe_php_register_variable(lbuf, cd, strlen(cd), NULL, 0); } /* Add $foo[type] */ @@ -1188,7 +1197,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); /* Restore Content-Type Header */ if (s != NULL) { @@ -1202,12 +1211,16 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ zval zfilename; /* Initialize variables */ - add_protected_variable(param TSRMLS_CC); + add_protected_variable(param); /* if param is of form xxx[.*] this will cut it to xxx */ if (!is_anonymous) { - ZVAL_STRING(&zfilename, temp_filename, 1); - safe_php_register_variable_ex(param, &zfilename, NULL, 1 TSRMLS_CC); + if (temp_filename) { + ZVAL_STR_COPY(&zfilename, temp_filename); + } else { + ZVAL_EMPTY_STRING(&zfilename); + } + safe_php_register_variable_ex(param, &zfilename, NULL, 1); } /* Add $foo[tmp_name] */ @@ -1216,9 +1229,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } else { 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); + add_protected_variable(lbuf); + if (temp_filename) { + ZVAL_STR_COPY(&zfilename, temp_filename); + } else { + ZVAL_EMPTY_STRING(&zfilename); + } + register_http_post_files_variable_ex(lbuf, &zfilename, &PG(http_globals)[TRACK_VARS_FILES], 1); } { @@ -1232,7 +1249,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'; @@ -1256,7 +1273,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); /* Add $foo_size */ if (is_arr_upload) { @@ -1266,9 +1283,9 @@ 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); + safe_php_register_variable_ex(lbuf, &file_size, NULL, size_overflow); } /* Add $foo[size] */ @@ -1278,9 +1295,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); } efree(param); } @@ -1291,7 +1308,7 @@ fileupload_done: multipart_event_end event_end; event_end.post_bytes_processed = SG(read_post_bytes); - php_rfc1867_callback(MULTIPART_EVENT_END, &event_end, &event_extra_data TSRMLS_CC); + php_rfc1867_callback(MULTIPART_EVENT_END, &event_end, &event_extra_data); } if (lbuf) efree(lbuf); |