Skip to content
Closed
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions Zend/tests/errmsg_046.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
errmsg: disabled eval function
--INI--
disable_functions=eval
--FILE--
<?php

eval('echo "Eval";');

echo "Done\n";
?>
--EXPECTF--
Warning: eval() has been disabled for security reasons in %s on line %d
Done
12 changes: 12 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,12 @@ ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_lengt

/* Disabled functions support */

zend_op_array *display_disabled_compile_string(zval *source_string, char *filename)
{
zend_error(E_WARNING, "eval() has been disabled for security reasons");
return NULL;
}

/* {{{ proto void display_disabled_function(void)
Dummy function which displays an error when a disabled function is called. */
ZEND_API ZEND_FUNCTION(display_disabled_function)
Copy link
Contributor

@carusogabriel carusogabriel Apr 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added display_disabled_compile_string function is because we can't use this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the signatures are different. display_disabled_function has the signature of an internal function and it can be replaced as function pointer in the function_table (see zend_disable_function just below this code in the same file).

The eval disable support makes use of the function pointer to zend_compile_string which can be replaced with different implementation using the same idea as the function table disable functionality.

Expand All @@ -2762,6 +2768,12 @@ ZEND_API ZEND_FUNCTION(display_disabled_function)
ZEND_API int zend_disable_function(char *function_name, size_t function_name_length) /* {{{ */
{
zend_internal_function *func;

if (strcmp(function_name, "eval") == 0) {
zend_compile_string = display_disabled_compile_string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a terrible idea. It makes Xdebug not being able to change variables, or allow for watches either, if eval is turned off this way. Xdebug uses zend_eval_string, which calls zend_compile_string that you now override with something broken. Not only that, as it is not easily chained, changing this back in an extension reliably is a pain. This should be reverted.

return SUCCESS;
}

if ((func = zend_hash_str_find_ptr(CG(function_table), function_name, function_name_length))) {
func->fn_flags &= ~(ZEND_ACC_VARIADIC | ZEND_ACC_HAS_TYPE_HINTS);
func->num_args = 0;
Expand Down