Skip to content

Commit 83cd2a7

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 79c0ba1 commit 83cd2a7

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
zend_observer_remove_begin_handler(func, observer_begin);
314314
zend_observer_remove_end_handler(func, observer_end);
315315
}
@@ -331,7 +331,7 @@ static ZEND_INI_MH(zend_test_observer_OnUpdateCommaList)
331331
zend_string_release(str);
332332
if (stage != PHP_INI_STAGE_STARTUP && stage != PHP_INI_STAGE_ACTIVATE && stage != PHP_INI_STAGE_DEACTIVATE && stage != PHP_INI_STAGE_SHUTDOWN) {
333333
ZEND_HASH_FOREACH_STR_KEY(*p, funcname) {
334-
if ((func = zend_hash_find_ptr(EG(function_table), funcname))) {
334+
if ((func = zend_hash_find_ptr(EG(function_table), funcname)) && ZEND_OBSERVER_DATA(func) != NULL) {
335335
zend_observer_add_begin_handler(func, observer_begin);
336336
zend_observer_add_end_handler(func, observer_end);
337337
}

0 commit comments

Comments
 (0)