Skip to content

Commit 8719baa

Browse files
committed
Ensure that the functions have already been called
We also need to ensure that the functions to observe have already been called, so that their begin and end handlers are properly initialized. Otherwise we will not observe the function execution, but a segfault.
1 parent 3d4f8e9 commit 8719baa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/zend_test/observer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static ZEND_INI_MH(zend_test_observer_OnUpdateCommaList)
309309
}
310310
if (stage != PHP_INI_STAGE_STARTUP && stage != PHP_INI_STAGE_ACTIVATE && stage != PHP_INI_STAGE_DEACTIVATE && stage != PHP_INI_STAGE_SHUTDOWN) {
311311
ZEND_HASH_FOREACH_STR_KEY(*p, funcname) {
312-
if ((func = zend_hash_find_ptr(EG(function_table), funcname))) {
312+
if ((func = zend_hash_find_ptr(EG(function_table), funcname)) && ZEND_OBSERVER_DATA(func) != NULL) {
313313
void *old_handler;
314314
zend_observer_remove_begin_handler(func, observer_begin, (zend_observer_fcall_begin_handler *)&old_handler);
315315
zend_observer_remove_end_handler(func, observer_end, (zend_observer_fcall_end_handler *)&old_handler);
@@ -332,7 +332,7 @@ static ZEND_INI_MH(zend_test_observer_OnUpdateCommaList)
332332
zend_string_release(str);
333333
if (stage != PHP_INI_STAGE_STARTUP && stage != PHP_INI_STAGE_ACTIVATE && stage != PHP_INI_STAGE_DEACTIVATE && stage != PHP_INI_STAGE_SHUTDOWN) {
334334
ZEND_HASH_FOREACH_STR_KEY(*p, funcname) {
335-
if ((func = zend_hash_find_ptr(EG(function_table), funcname))) {
335+
if ((func = zend_hash_find_ptr(EG(function_table), funcname)) && ZEND_OBSERVER_DATA(func) != NULL) {
336336
zend_observer_add_begin_handler(func, observer_begin);
337337
zend_observer_add_end_handler(func, observer_end);
338338
}

0 commit comments

Comments
 (0)