Skip to content

Commit 6df1311

Browse files
Merge branch 'PHP-8.5'
* PHP-8.5: Keep EG(errors) buffer consistent on erealloc failure (#23257)
2 parents 3d3d336 + dab13a0 commit 6df1311

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
@@ -1487,13 +1487,14 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
14871487
info->lineno = error_lineno;
14881488
info->filename = zend_string_copy(error_filename);
14891489
info->message = zend_string_copy(message);
1490-
EG(errors).size++;
1491-
if (EG(errors).size > EG(errors).capacity) {
1490+
uint32_t new_size = EG(errors).size + 1;
1491+
if (new_size > EG(errors).capacity) {
14921492
uint32_t capacity = EG(errors).capacity ? EG(errors).capacity + (EG(errors).capacity >> 1) : 2;
14931493
EG(errors).errors = erealloc(EG(errors).errors, sizeof(zend_error_info *) * capacity);
14941494
EG(errors).capacity = capacity;
14951495
}
1496-
EG(errors).errors[EG(errors).size - 1] = info;
1496+
EG(errors).errors[EG(errors).size] = info;
1497+
EG(errors).size = new_size;
14971498

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

0 commit comments

Comments
 (0)