diff options
author | Stanislav Malyshev <stas@php.net> | 2015-05-12 14:26:06 -0700 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2015-05-12 14:26:06 -0700 |
commit | 587ddf6ddccd707d67d48dccd4f4ca0a90224ac9 (patch) | |
tree | cf67e35a6088482a23861f25fe8e01a3213bb717 /main | |
parent | adbb301a70e16ada22f14a7e623b73d84580f12d (diff) | |
parent | c08f9c2c786b0f7cbb401c18f6634cb5773f5baf (diff) | |
download | php-git-587ddf6ddccd707d67d48dccd4f4ca0a90224ac9.tar.gz |
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5:
fix format
update NEWS
Add test for bug #69522
Update tests
Fix bug #69522 - do not allow int overflow
Forgot test file
Fix bug #69403 and other int overflows
Fixed bug #69418 - more s->p fixes for filenames
Fixed bug #69364 - use smart_str to assemble strings
Fix bug #69453 - don't try to cut empty string
Fix bug #69545 - avoid overflow when reading list
Conflicts:
ext/standard/pack.c
Diffstat (limited to 'main')
-rw-r--r-- | main/rfc1867.c | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/main/rfc1867.c b/main/rfc1867.c index 919768e171..ca8f28b553 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -33,6 +33,7 @@ #include "php_variables.h" #include "rfc1867.h" #include "ext/standard/php_string.h" +#include "ext/standard/php_smart_str.h" #if defined(PHP_WIN32) && !defined(HAVE_ATOLL) # define atoll(s) _atoi64(s) @@ -403,8 +404,9 @@ static int find_boundary(multipart_buffer *self, char *boundary TSRMLS_DC) static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC) { char *line; - mime_header_entry prev_entry = {0}, entry; - int prev_len, cur_len; + mime_header_entry entry = {0}; + smart_str buf_value = {0}; + char *key = NULL; /* didn't find boundary, abort */ if (!find_boundary(self, self->boundary TSRMLS_CC)) { @@ -416,11 +418,10 @@ static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header T while( (line = get_line(self TSRMLS_CC)) && line[0] != '\0' ) { /* add header to table */ - char *key = line; char *value = NULL; if (php_rfc1867_encoding_translation(TSRMLS_C)) { - self->input_encoding = zend_multibyte_encoding_detector(line, strlen(line), self->detect_order, self->detect_order_size TSRMLS_CC); + self->input_encoding = zend_multibyte_encoding_detector((unsigned char *)line, strlen(line), self->detect_order, self->detect_order_size TSRMLS_CC); } /* space in the beginning means same header */ @@ -429,31 +430,33 @@ static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header T } if (value) { - *value = 0; - do { value++; } while(isspace(*value)); - - entry.value = estrdup(value); - entry.key = estrdup(key); - - } 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); - - entry.value = emalloc(prev_len + cur_len + 1); - memcpy(entry.value, prev_entry.value, prev_len); - memcpy(entry.value + prev_len, line, cur_len); - entry.value[cur_len + prev_len] = '\0'; + if(buf_value.c && key) { + /* new entry, add the old one to the list */ + smart_str_0(&buf_value); + entry.key = key; + entry.value = buf_value.c; + zend_llist_add_element(header, &entry); + buf_value.c = NULL; + key = NULL; + } - entry.key = estrdup(prev_entry.key); + *value = '\0'; + do { value++; } while(isspace(*value)); - zend_llist_remove_tail(header); + key = estrdup(line); + smart_str_appends(&buf_value, value); + } else if (buf_value.c) { /* If no ':' on the line, add to previous line */ + smart_str_appends(&buf_value, line); } else { continue; } - + } + if(buf_value.c && key) { + /* add the last one to the list */ + smart_str_0(&buf_value); + entry.key = key; + entry.value = buf_value.c; zend_llist_add_element(header, &entry); - prev_entry = entry; } return 1; @@ -890,7 +893,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ 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)); } - + if (php_rfc1867_callback != NULL) { multipart_event_formdata event_formdata; |