Skip to content

Commit c338057

Browse files
authored
sapi/fuzzer: Fetch function and call it directly instead of using a zval to hold the name (#19030)
1 parent 5a2a150 commit c338057

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

sapi/fuzzer/fuzzer-execute-common.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,16 @@ ZEND_ATTRIBUTE_UNUSED static void create_file(void) {
127127
ZEND_ATTRIBUTE_UNUSED static void opcache_invalidate(void) {
128128
steps_left = MAX_STEPS;
129129
zend_exception_save();
130-
zval retval, func, args[2];
131-
ZVAL_STRING(&func, "opcache_invalidate");
130+
zval retval, args[2];
131+
zend_function *fn = zend_hash_str_find_ptr(CG(function_table), ZEND_STRL("opcache_invalidate"));
132+
ZEND_ASSERT(fn != NULL);
133+
132134
ZVAL_STRING(&args[0], FILE_NAME);
133135
ZVAL_TRUE(&args[1]);
134-
call_user_function(CG(function_table), NULL, &func, &retval, 2, args);
136+
zend_call_known_function(fn, NULL, NULL, &retval, 2, args, NULL);
135137
ZEND_ASSERT(Z_TYPE(retval) == IS_TRUE);
136138
zval_ptr_dtor(&args[0]);
137139
zval_ptr_dtor(&retval);
138-
zval_ptr_dtor(&func);
139140
zend_exception_restore();
140141
}
141142

sapi/fuzzer/fuzzer-sapi.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,20 @@ int fuzzer_do_request_from_buffer(
292292

293293
// Call named PHP function with N zval arguments
294294
void fuzzer_call_php_func_zval(const char *func_name, int nargs, zval *args) {
295-
zval retval, func;
295+
zval retval;
296+
297+
zend_function *fn = zend_hash_str_find_ptr(CG(function_table), func_name, strlen(func_name));
298+
ZEND_ASSERT(fn != NULL);
296299

297-
ZVAL_STRING(&func, func_name);
298300
ZVAL_UNDEF(&retval);
299-
call_user_function(CG(function_table), NULL, &func, &retval, nargs, args);
301+
zend_call_known_function(fn, NULL, NULL, &retval, nargs, args, NULL);
300302

301303
// TODO: check result?
302304
/* to ensure retval is not broken */
303305
php_var_dump(&retval, 0);
304306

305307
/* cleanup */
306308
zval_ptr_dtor(&retval);
307-
zval_ptr_dtor(&func);
308309
}
309310

310311
// Call named PHP function with N string arguments

0 commit comments

Comments
 (0)