[php-src] PR #11957: Fix GH-11874: intl causing segfault with temporaries
| From: | nielsdos | Date: | Sun, 13 Aug 2023 15:36:21 +0000 |
| Subject: | [php-src] PR #11957: Fix GH-11874: intl causing segfault with temporaries | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-23363@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/11957
Author: nielsdos
The segfault happens because zoi->wrapping_obj points to an object that has been freed. This
wrapping_obj is set in
IntlIterator_from_StringEnumeration(). Notice how the refcount is not increased in this function. By
switching to ZVAL_OBJ_COPY, the segfault disappears. However, now we get memleaks.
The reason we get a memleak is because now we're responsible for destroying the reference copy
we made with ZVAL_OBJ_COPY. It would appear this would already be done in zoi_with_current_dtor.
This did work in the past for CVs because the live variable cleanup when the CV gets destroyed would
set the object to UNDEF.
To add more confusion:
The zoi_with_current_dtor() comments seem to indicate that it can be called twice. However, that
seems to be _not_ the case as it's the dtor for zend_object_iterator_funcs.
This patch reworks how the destruction works in addition to the ZVAL_OBJ_COPY change.
I checked other of wrapping_obj. The only other place is in BreakIterator. BreakIterator
doesn't actually use the wrapping_obj for anything however, and doesn't manage that
refcount, so set it to UNDEF to be safe.
-------
I'm not 100% confident in this patch, I haven't worked a lot with the intl extension
before.