Skip to content

Commit 5edfc63

Browse files
committed
Keep EG(errors) buffer consistent on alloc failure
Update the error count only after the buffer has been resized and the new entry initialized. This prevents fatal error handling from reading past the buffer if reallocating it triggers an OOM bailout.
1 parent daeeed8 commit 5edfc63

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Zend/zend.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,9 +1486,10 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
14861486

14871487
/* This is very inefficient for a large number of errors.
14881488
* Use pow2 realloc if it becomes a problem. */
1489-
EG(num_errors)++;
1490-
EG(errors) = erealloc(EG(errors), sizeof(zend_error_info*) * EG(num_errors));
1491-
EG(errors)[EG(num_errors)-1] = info;
1489+
uint32_t new_num_errors = EG(num_errors) + 1;
1490+
EG(errors) = erealloc(EG(errors), sizeof(zend_error_info*) * new_num_errors);
1491+
EG(errors)[EG(num_errors)] = info;
1492+
EG(num_errors) = new_num_errors;
14921493

14931494
/* Do not process non-fatal recorded error */
14941495
if (!(type & E_FATAL_ERRORS) || (type & E_DONT_BAIL)) {

0 commit comments

Comments
 (0)