Skip to content

Fix GH-17938: UAF with zend_test opline observer and magic_quotes_gpc=1 #17958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ void * zend_test_custom_realloc(void * ptr, size_t len)
return _zend_mm_realloc(ZT_G(zend_orig_heap), ptr, len ZEND_FILE_LINE_EMPTY_CC ZEND_FILE_LINE_EMPTY_CC);
}

static void zend_test_reset_heap(zend_zend_test_globals *zend_test_globals)
{
if (zend_test_globals->zend_test_heap) {
free(zend_test_globals->zend_test_heap);
zend_test_globals->zend_test_heap = NULL;
zend_mm_set_heap(zend_test_globals->zend_orig_heap);
}
}

static PHP_INI_MH(OnUpdateZendTestObserveOplineInZendMM)
{
if (new_value == NULL) {
Expand All @@ -687,10 +696,8 @@ static PHP_INI_MH(OnUpdateZendTestObserveOplineInZendMM)
);
ZT_G(zend_orig_heap) = zend_mm_get_heap();
zend_mm_set_heap(ZT_G(zend_test_heap));
} else if (ZT_G(zend_test_heap)) {
free(ZT_G(zend_test_heap));
ZT_G(zend_test_heap) = NULL;
zend_mm_set_heap(ZT_G(zend_orig_heap));
} else {
zend_test_reset_heap(ZEND_MODULE_GLOBALS_BULK(zend_test));
}
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
}
Expand Down Expand Up @@ -1339,6 +1346,7 @@ static PHP_GINIT_FUNCTION(zend_test)
static PHP_GSHUTDOWN_FUNCTION(zend_test)
{
zend_test_observer_gshutdown(zend_test_globals);
zend_test_reset_heap(zend_test_globals);
}

PHP_MINFO_FUNCTION(zend_test)
Expand Down
Loading