Last active
August 29, 2015 14:23
-
-
Save castor4bit/ec28eebc6df551c69c0f to your computer and use it in GitHub Desktop.
CVE-2015-4024.patch (PHP5.2/5.3) ** Use at your own risk. **
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ../php-5.2.17/main/rfc1867.c 2010-03-18 18:37:25.000000000 -0400 | |
+++ main/rfc1867.c 2015-06-18 22:06:43.613999937 -0400 | |
@@ -34,6 +34,7 @@ | |
#include "rfc1867.h" | |
#include "php_ini.h" | |
#include "ext/standard/php_string.h" | |
+#include "ext/standard/php_smart_str.h" | |
#define DEBUG_FILE_UPLOAD ZEND_DEBUG | |
@@ -463,8 +464,9 @@ | |
static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC) | |
{ | |
char *line; | |
- mime_header_entry prev_entry, 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)) { | |
@@ -476,7 +478,6 @@ | |
while( (line = get_line(self TSRMLS_CC)) && strlen(line) > 0 ) | |
{ | |
/* add header to table */ | |
- char *key = line; | |
char *value = NULL; | |
/* space in the beginning means same header */ | |
@@ -485,31 +486,33 @@ | |
} | |
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ../php-5.3.29/main/rfc1867.c 2014-08-13 15:22:50.000000000 -0400 | |
+++ main/rfc1867.c 2015-06-18 23:18:48.784999960 -0400 | |
@@ -33,6 +33,7 @@ | |
#include "php_variables.h" | |
#include "rfc1867.h" | |
#include "ext/standard/php_string.h" | |
+#include "ext/standard/php_smart_str.h" | |
#define DEBUG_FILE_UPLOAD ZEND_DEBUG | |
@@ -462,8 +463,9 @@ | |
static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC) | |
{ | |
char *line; | |
- mime_header_entry prev_entry, 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)) { | |
@@ -475,7 +477,6 @@ | |
while( (line = get_line(self TSRMLS_CC)) && strlen(line) > 0 ) | |
{ | |
/* add header to table */ | |
- char *key = line; | |
char *value = NULL; | |
/* space in the beginning means same header */ | |
@@ -484,31 +485,33 @@ | |
} | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment