Skip to content

Commit 74b5662

Browse files
smalyshevweltling
authored andcommitted
Fix bug #73190: memcpy negative parameter _bc_new_num_ex
(cherry picked from commit 40e7baa)
1 parent f42cbd7 commit 74b5662

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Zend/zend_exceptions.c

+21-5
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,7 @@ ZEND_METHOD(exception, __construct)
293293
#define CHECK_EXC_TYPE(name, type) \
294294
pvalue = zend_read_property(i_get_exception_base(object), (object), name, sizeof(name) - 1, 1, &value); \
295295
if (Z_TYPE_P(pvalue) != IS_NULL && Z_TYPE_P(pvalue) != type) { \
296-
zval tmp; \
297-
ZVAL_STRINGL(&tmp, name, sizeof(name) - 1); \
298-
Z_OBJ_HANDLER_P(object, unset_property)(object, &tmp, NULL); \
299-
zval_ptr_dtor(&tmp); \
296+
zend_unset_property(i_get_exception_base(object), object, name, sizeof(name)-1); \
300297
}
301298

302299
ZEND_METHOD(exception, __wakeup)
@@ -309,7 +306,12 @@ ZEND_METHOD(exception, __wakeup)
309306
CHECK_EXC_TYPE("file", IS_STRING);
310307
CHECK_EXC_TYPE("line", IS_LONG);
311308
CHECK_EXC_TYPE("trace", IS_ARRAY);
312-
CHECK_EXC_TYPE("previous", IS_OBJECT);
309+
pvalue = zend_read_property(i_get_exception_base(object), object, "previous", sizeof("previous")-1, 1, &value);
310+
if (pvalue && Z_TYPE_P(pvalue) != IS_NULL && (Z_TYPE_P(pvalue) != IS_OBJECT ||
311+
!instanceof_function(Z_OBJCE_P(pvalue), i_get_exception_base(object)) ||
312+
pvalue == object)) {
313+
zend_unset_property(i_get_exception_base(object), object, "previous", sizeof("previous")-1);
314+
}
313315
}
314316
/* }}} */
315317

@@ -771,10 +773,24 @@ ZEND_METHOD(exception, __toString)
771773
zend_string_release(file);
772774
zval_ptr_dtor(&trace);
773775

776+
Z_OBJPROP_P(exception)->u.v.nApplyCount++;
774777
exception = GET_PROPERTY(exception, "previous");
778+
if (exception && Z_TYPE_P(exception) == IS_OBJECT && Z_OBJPROP_P(exception)->u.v.nApplyCount > 0) {
779+
exception = NULL;
780+
}
775781
}
776782
zval_dtor(&fname);
777783

784+
/* Reset apply counts */
785+
while (exception && Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(exception)) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
786+
if(Z_OBJPROP_P(exception)->u.v.nApplyCount) {
787+
Z_OBJPROP_P(exception)->u.v.nApplyCount--;
788+
} else {
789+
break;
790+
}
791+
exception = GET_PROPERTY(exception, "previous");
792+
}
793+
778794
exception = getThis();
779795
base_ce = i_get_exception_base(exception);
780796

ext/bcmath/libbcmath/src/init.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ _bc_new_num_ex (length, scale, persistent)
4949
int length, scale, persistent;
5050
{
5151
bc_num temp;
52-
52+
/* PHP Change: add length check */
53+
if ((size_t)length+(size_t)scale > INT_MAX) {
54+
zend_error(E_ERROR, "Result too long, max is %d", INT_MAX);
55+
}
5356
/* PHP Change: malloc() -> pemalloc(), removed free_list code */
5457
temp = (bc_num) safe_pemalloc (1, sizeof(bc_struct)+length, scale, persistent);
5558
#if 0

ext/bcmath/libbcmath/src/outofmem.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,5 @@
4141

4242
void bc_out_of_memory (void)
4343
{
44-
(void) fprintf (stderr, "bcmath: out of memory!\n");
45-
exit (1);
44+
zend_error_noreturn(E_ERROR, "bcmath: out of memory!");
4645
}

0 commit comments

Comments
 (0)