Skip to content

Commit 41fc3c7

Browse files
committed
Add check for string overflow to all string add operations
1 parent abd159c commit 41fc3c7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Zend/zend_operators.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,10 @@ ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2)
12541254
int length = Z_STRLEN_P(op1) + 1;
12551255
char *buf;
12561256

1257+
if (UNEXPECTED(length < 0)) {
1258+
zend_error(E_ERROR, "String size overflow");
1259+
}
1260+
12571261
if (IS_INTERNED(Z_STRVAL_P(op1))) {
12581262
buf = (char *) emalloc(length + 1);
12591263
memcpy(buf, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
@@ -1273,6 +1277,9 @@ ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2
12731277
int length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
12741278
char *buf;
12751279

1280+
if (UNEXPECTED(length < 0)) {
1281+
zend_error(E_ERROR, "String size overflow");
1282+
}
12761283
if (IS_INTERNED(Z_STRVAL_P(op1))) {
12771284
buf = (char *) emalloc(length+1);
12781285
memcpy(buf, Z_STRVAL_P(op1), Z_STRLEN_P(op1));

0 commit comments

Comments
 (0)