2

I can't figure out how to call an existing PHP function, everytime I end up either with a segmentation fault or a Fatal error. Disclaimer: I'm not experienced at all in low level programming, just learning and trying things.

I tried different ways, for example with phpinfo():

/* zend_compile.c (in a custom function that works well without the code below) */
zend_string *func_name;
zend_ast *func_name_ast, *args_ast_list, *arg_ast;
zend_ast_list *args_list;
znode func_name_node, arg_node;

func_name = zend_string_init("phpinfo", sizeof("phpinfo"), 0);
func_name_ast = zend_ast_create_zval_from_str(func_name);
zend_compile_expr(&func_name_node, func_name_ast);

arg_ast = zend_ast_create_zval_from_long(0);
zend_compile_expr(&arg_node, arg_ast);

args_ast_list = zend_ast_create_list(2, ZEND_AST_ARG_LIST, func_name_ast, arg_ast);
args_list = zend_ast_get_list(args_ast_list);

zend_compile_func_cuf(NULL, args_list, func_name);

Result: Fatal error: Uncaught TypeError: phpinfo(): Argument #1 ($function) must be a valid callback, function "phpinfo" not found or invalid function name.

Also trying to find the function in the hashtable fails:

zend_string *func_name, *lcname;
zval *name;
zend_function *fbc;

func_name = zend_string_init("phpinfo", sizeof("phpinfo"), 0);
func_name_ast = zend_ast_create_zval_from_str(func_name);
zend_compile_expr(&func_name_node, func_name_ast);

name = &func_name_node.u.constant;
lcname = zend_string_tolower(Z_STR_P(name));
fbc = zend_hash_find_ptr(&CG(function_table), lcname);

Result: segmentation fault

I also tried call_user_function like this example https://stackoverflow.com/a/13593387/1159013 but it leads to a segmentation fault as well.

Calling each opcodes individually also leads to errors above.

How to call a PHP function from zend_compile.c?

0

Browse other questions tagged or ask your own question.