Skip to content

Commit 6e12e49

Browse files
committed
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6: More string length checks & fixes
2 parents 7f2b7a4 + ea9fac9 commit 6e12e49

File tree

7 files changed

+20
-8
lines changed

7 files changed

+20
-8
lines changed

ext/imap/php_imap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3950,7 +3950,7 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
39503950
#define PHP_IMAP_CLEAN if (bufferTo) efree(bufferTo); if (bufferCc) efree(bufferCc); if (bufferBcc) efree(bufferBcc); if (bufferHeader) efree(bufferHeader);
39513951
#define PHP_IMAP_BAD_DEST PHP_IMAP_CLEAN; efree(tempMailTo); return (BAD_MSG_DESTINATION);
39523952

3953-
bufferHeader = (char *)emalloc(bufferLen + 1);
3953+
bufferHeader = (char *)safe_emalloc(bufferLen, 1, 1);
39543954
memset(bufferHeader, 0, bufferLen);
39553955
if (to && *to) {
39563956
strlcat(bufferHeader, "To: ", bufferLen + 1);

ext/intl/intl_convert.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void intl_convert_utf8_to_utf16(
5353
UErrorCode* status )
5454
{
5555
UChar* dst_buf = NULL;
56-
int32_t dst_len = 0;
56+
uint32_t dst_len = 0;
5757

5858
/* If *target is NULL determine required destination buffer size (pre-flighting).
5959
* Otherwise, attempt to convert source string; if *target buffer is not large enough

ext/intl/locale/locale_methods.c

+7
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ static zend_string* get_icu_value_internal( const char* loc_name , char* tag_nam
268268
int32_t buflen = 512;
269269
UErrorCode status = U_ZERO_ERROR;
270270

271+
if (strlen(loc_name) > INTL_MAX_LOCALE_LEN) {
272+
return NULL;
273+
}
271274

272275
if( strcmp(tag_name, LOC_CANONICALIZE_TAG) != 0 ){
273276
/* Handle grandfathered languages */
@@ -713,6 +716,8 @@ PHP_FUNCTION( locale_get_keywords )
713716
RETURN_FALSE;
714717
}
715718

719+
INTL_CHECK_LOCALE_LEN(strlen(loc_name));
720+
716721
if(loc_name_len == 0) {
717722
loc_name = intl_locale_get_default();
718723
}
@@ -1120,6 +1125,8 @@ PHP_FUNCTION(locale_parse)
11201125
RETURN_FALSE;
11211126
}
11221127

1128+
INTL_CHECK_LOCALE_LEN(strlen(loc_name));
1129+
11231130
if(loc_name_len == 0) {
11241131
loc_name = intl_locale_get_default();
11251132
}

ext/intl/msgformat/msgformat_data.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ msgformat_data* msgformat_data_create( void )
8383
int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec)
8484
{
8585
if(*spattern && *spattern_len && u_strchr(*spattern, (UChar)'\'')) {
86-
UChar *npattern = emalloc(sizeof(UChar)*(2*(*spattern_len)+1));
86+
UChar *npattern = safe_emalloc(sizeof(UChar)*2, *spattern_len, sizeof(UChar));
8787
uint32_t npattern_len;
8888
npattern_len = umsg_autoQuoteApostrophe(*spattern, *spattern_len, npattern, 2*(*spattern_len)+1, ec);
8989
efree(*spattern);

ext/xmlrpc/libxmlrpc/base64.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static const char rcsid[] = "#(@) $Id$";
1515
/* ENCODE -- Encode binary file into base64. */
1616
#include <stdlib.h>
1717
#include <ctype.h>
18+
#include <limits.h>
1819

1920
#include "base64.h"
2021

@@ -31,6 +32,9 @@ void buffer_new(struct buffer_st *b)
3132

3233
void buffer_add(struct buffer_st *b, char c)
3334
{
35+
if ((INT_MAX - b->length) <= 512) {
36+
return;
37+
}
3438
*(b->ptr++) = c;
3539
b->offset++;
3640
if (b->offset == b->length) {
@@ -79,7 +83,7 @@ void base64_encode_xmlrpc(struct buffer_st *b, const char *source, int length)
7983
for (n = 0; n < 3; n++) {
8084
c = *(source++);
8185
offset++;
82-
if (offset > length) {
86+
if (offset > length || offset <= 0) {
8387
hiteof = 1;
8488
break;
8589
}

ext/xmlrpc/libxmlrpc/simplestring.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static const char rcsid[] = "#(@) $Id$";
8080

8181
#include <stdlib.h>
8282
#include <string.h>
83+
#include <limits.h>
8384
#include "simplestring.h"
8485

8586
#define my_free(thing) if(thing) {free(thing); thing = 0;}
@@ -200,7 +201,7 @@ void simplestring_addn(simplestring* target, const char* source, size_t add_len)
200201
simplestring_init_str(target);
201202
}
202203

203-
if((SIZE_MAX - add_len) < target->len || (SIZE_MAX - add_len - 1) < target->len) {
204+
if((INT_MAX - add_len) < target->len || (INT_MAX - add_len - 1) < target->len) {
204205
/* check for overflows, if there's a potential overflow do nothing */
205206
return;
206207
}

ext/zip/php_zip.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
15901590
}
15911591

15921592
if (dirname[dirname_len-1] != '/') {
1593-
s=(char *)emalloc(dirname_len+2);
1593+
s=(char *)safe_emalloc(dirname_len, 1, 2);
15941594
strcpy(s, dirname);
15951595
s[dirname_len] = '/';
15961596
s[dirname_len+1] = '\0';
@@ -1805,14 +1805,14 @@ static ZIPARCHIVE_METHOD(addFromString)
18051805

18061806
ze_obj = Z_ZIP_P(self);
18071807
if (ze_obj->buffers_cnt) {
1808-
ze_obj->buffers = (char **)erealloc(ze_obj->buffers, sizeof(char *) * (ze_obj->buffers_cnt+1));
1808+
ze_obj->buffers = (char **)safe_erealloc(ze_obj->buffers, sizeof(char *), (ze_obj->buffers_cnt+1), 0);
18091809
pos = ze_obj->buffers_cnt++;
18101810
} else {
18111811
ze_obj->buffers = (char **)emalloc(sizeof(char *));
18121812
ze_obj->buffers_cnt++;
18131813
pos = 0;
18141814
}
1815-
ze_obj->buffers[pos] = (char *)emalloc(ZSTR_LEN(buffer) + 1);
1815+
ze_obj->buffers[pos] = (char *)safe_emalloc(ZSTR_LEN(buffer), 1, 1);
18161816
memcpy(ze_obj->buffers[pos], ZSTR_VAL(buffer), ZSTR_LEN(buffer) + 1);
18171817

18181818
zs = zip_source_buffer(intern, ze_obj->buffers[pos], ZSTR_LEN(buffer), 0);

0 commit comments

Comments
 (0)