|
|
af9dc8 |
From 4605d536d23b00813d11cc906bb48d39bdcf5f25 Mon Sep 17 00:00:00 2001
|
|
|
af9dc8 |
From: Stanislav Malyshev <stas@php.net>
|
|
|
af9dc8 |
Date: Sat, 9 May 2015 23:04:25 -0700
|
|
|
af9dc8 |
Subject: [PATCH] Fixed bug #69364 - use smart_str to assemble strings
|
|
|
af9dc8 |
|
|
|
af9dc8 |
---
|
|
|
af9dc8 |
main/rfc1867.c | 51 +++++++++++++++++++++++++++------------------------
|
|
|
af9dc8 |
1 file changed, 27 insertions(+), 24 deletions(-)
|
|
|
af9dc8 |
|
|
|
af9dc8 |
diff --git a/main/rfc1867.c b/main/rfc1867.c
|
|
|
af9dc8 |
index fab199b..9e2fbd5 100644
|
|
|
af9dc8 |
--- a/main/rfc1867.c
|
|
|
af9dc8 |
+++ b/main/rfc1867.c
|
|
|
af9dc8 |
@@ -33,6 +33,7 @@
|
|
|
af9dc8 |
#include "php_variables.h"
|
|
|
af9dc8 |
#include "rfc1867.h"
|
|
|
af9dc8 |
#include "ext/standard/php_string.h"
|
|
|
af9dc8 |
+#include "ext/standard/php_smart_str.h"
|
|
|
af9dc8 |
|
|
|
af9dc8 |
#define DEBUG_FILE_UPLOAD ZEND_DEBUG
|
|
|
af9dc8 |
|
|
|
af9dc8 |
@@ -398,8 +399,9 @@ static int find_boundary(multipart_buffe
|
|
|
af9dc8 |
static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC)
|
|
|
af9dc8 |
{
|
|
|
af9dc8 |
char *line;
|
|
|
af9dc8 |
- mime_header_entry prev_entry, entry;
|
|
|
af9dc8 |
- int prev_len, cur_len;
|
|
|
af9dc8 |
+ mime_header_entry entry = {0};
|
|
|
af9dc8 |
+ smart_str buf_value = {0};
|
|
|
af9dc8 |
+ char *key = NULL;
|
|
|
af9dc8 |
|
|
|
af9dc8 |
/* didn't find boundary, abort */
|
|
|
af9dc8 |
if (!find_boundary(self, self->boundary TSRMLS_CC)) {
|
|
|
af9dc8 |
@@ -411,11 +413,10 @@ static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header T
|
|
|
af9dc8 |
while( (line = get_line(self TSRMLS_CC)) && strlen(line) > 0 )
|
|
|
af9dc8 |
{
|
|
|
af9dc8 |
/* add header to table */
|
|
|
af9dc8 |
- char *key = line;
|
|
|
af9dc8 |
char *value = NULL;
|
|
|
af9dc8 |
|
|
|
af9dc8 |
if (php_rfc1867_encoding_translation(TSRMLS_C)) {
|
|
|
af9dc8 |
- self->input_encoding = zend_multibyte_encoding_detector(line, strlen(line), self->detect_order, self->detect_order_size TSRMLS_CC);
|
|
|
af9dc8 |
+ self->input_encoding = zend_multibyte_encoding_detector((unsigned char *)line, strlen(line), self->detect_order, self->detect_order_size TSRMLS_CC);
|
|
|
af9dc8 |
}
|
|
|
af9dc8 |
|
|
|
af9dc8 |
/* space in the beginning means same header */
|
|
|
af9dc8 |
@@ -424,31 +425,33 @@ static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header T
|
|
|
af9dc8 |
}
|
|
|
af9dc8 |
|
|
|
af9dc8 |
if (value) {
|
|
|
af9dc8 |
- *value = 0;
|
|
|
af9dc8 |
- do { value++; } while(isspace(*value));
|
|
|
af9dc8 |
-
|
|
|
af9dc8 |
- entry.value = estrdup(value);
|
|
|
af9dc8 |
- entry.key = estrdup(key);
|
|
|
af9dc8 |
-
|
|
|
af9dc8 |
- } else if (zend_llist_count(header)) { /* If no ':' on the line, add to previous line */
|
|
|
af9dc8 |
-
|
|
|
af9dc8 |
- prev_len = strlen(prev_entry.value);
|
|
|
af9dc8 |
- cur_len = strlen(line);
|
|
|
af9dc8 |
-
|
|
|
af9dc8 |
- entry.value = emalloc(prev_len + cur_len + 1);
|
|
|
af9dc8 |
- memcpy(entry.value, prev_entry.value, prev_len);
|
|
|
af9dc8 |
- memcpy(entry.value + prev_len, line, cur_len);
|
|
|
af9dc8 |
- entry.value[cur_len + prev_len] = '\0';
|
|
|
af9dc8 |
+ if(buf_value.c && key) {
|
|
|
af9dc8 |
+ /* new entry, add the old one to the list */
|
|
|
af9dc8 |
+ smart_str_0(&buf_value);
|
|
|
af9dc8 |
+ entry.key = key;
|
|
|
af9dc8 |
+ entry.value = buf_value.c;
|
|
|
af9dc8 |
+ zend_llist_add_element(header, &entry);
|
|
|
af9dc8 |
+ buf_value.c = NULL;
|
|
|
af9dc8 |
+ key = NULL;
|
|
|
af9dc8 |
+ }
|
|
|
af9dc8 |
|
|
|
af9dc8 |
- entry.key = estrdup(prev_entry.key);
|
|
|
af9dc8 |
+ *value = '\0';
|
|
|
af9dc8 |
+ do { value++; } while(isspace(*value));
|
|
|
af9dc8 |
|
|
|
af9dc8 |
- zend_llist_remove_tail(header);
|
|
|
af9dc8 |
+ key = estrdup(line);
|
|
|
af9dc8 |
+ smart_str_appends(&buf_value, value);
|
|
|
af9dc8 |
+ } else if (buf_value.c) { /* If no ':' on the line, add to previous line */
|
|
|
af9dc8 |
+ smart_str_appends(&buf_value, line);
|
|
|
af9dc8 |
} else {
|
|
|
af9dc8 |
continue;
|
|
|
af9dc8 |
}
|
|
|
af9dc8 |
-
|
|
|
af9dc8 |
+ }
|
|
|
af9dc8 |
+ if(buf_value.c && key) {
|
|
|
af9dc8 |
+ /* add the last one to the list */
|
|
|
af9dc8 |
+ smart_str_0(&buf_value);
|
|
|
af9dc8 |
+ entry.key = key;
|
|
|
af9dc8 |
+ entry.value = buf_value.c;
|
|
|
af9dc8 |
zend_llist_add_element(header, &entry);
|
|
|
af9dc8 |
- prev_entry = entry;
|
|
|
af9dc8 |
}
|
|
|
af9dc8 |
|
|
|
af9dc8 |
return 1;
|
|
|
af9dc8 |
@@ -884,7 +887,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
|
|
|
af9dc8 |
if (count == PG(max_input_vars) + 1) {
|
|
|
af9dc8 |
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));
|
|
|
af9dc8 |
}
|
|
|
af9dc8 |
-
|
|
|
af9dc8 |
+
|
|
|
af9dc8 |
if (php_rfc1867_callback != NULL) {
|
|
|
af9dc8 |
multipart_event_formdata event_formdata;
|
|
|
af9dc8 |
|
|
|
af9dc8 |
--
|
|
|
af9dc8 |
2.1.4
|
|
|
af9dc8 |
|