com php-src: Fixed bug #69315: Zend/tests/bug69315.phpt Zend/zend_compile.c ext/opcache/Optimizer/pass1_5 .c ext/opcache/Optimizer/zend_optimizer.c
ext/opcache /Optimizer/zend_optimizer_internal.h
| From: | Xinchen Hui | Date: | Fri, 27 Mar 2015 09:50:36 +0000 |
| Subject: | com php-src: Fixed bug #69315: Zend/tests/bug69315.phpt Zend/zend_compile.c ext/opcache/Optimizer/pass1_5 .c ext/opcache/Optimizer/zend_optimizer.c ext/opcache /Optimizer/zend_optimizer_internal.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85900@lists.php.net to get a copy of this message | ||
Commit: 84d9426730fc1e7063cdc4fb0c25f8f382202431
Author: Xinchen Hui <laruence@gmail.com> Fri, 27 Mar 2015 17:50:36 +0800
Parents: d9d74d37ac2de7267b3c9904bb6e77c231f4973a
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=84d9426730fc1e7063cdc4fb0c25f8f382202431
Log:
Fixed bug #69315
Bugs:
https://bugs.php.net/69315
Changed paths:
A Zend/tests/bug69315.phpt
M Zend/zend_compile.c
M ext/opcache/Optimizer/pass1_5.c
M ext/opcache/Optimizer/zend_optimizer.c
M ext/opcache/Optimizer/zend_optimizer_internal.h
Diff:
diff --git a/Zend/tests/bug69315.phpt b/Zend/tests/bug69315.phpt
new file mode 100644
index 0000000..91f7ad8
--- /dev/null
+++ b/Zend/tests/bug69315.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Bug #69315 (disable_functions behaviors inconsistently)
+--INI--
+disable_functions=strlen,defined,call_user_func,constant,is_callable,is_string
+--FILE--
+<?php
+
+var_dump(function_exists("strlen"));
+var_dump(is_callable("strlen"));
+var_dump(strlen("xxx"));
+var_dump(defined("PHP_VERSION"));
+var_dump(constant("PHP_VERSION"));
+var_dump(call_user_func("strlen"));
+var_dump(is_string("xxx"));
+
+--EXPECTF--
+bool(false)
+bool(true)
+
+Warning: strlen() has been disabled for security reasons in %sbug69315.php on line %d
+NULL
+
+Warning: defined() has been disabled for security reasons in %sbug69315.php on line %d
+NULL
+
+Warning: constant() has been disabled for security reasons in %sbug69315.php on line %d
+NULL
+
+Warning: call_user_func() has been disabled for security reasons in %sbug69315.php on line %d
+NULL
+
+Warning: is_string() has been disabled for security reasons in %sbug69315.php on line %d
+NULL
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index de8a89d..cb53688 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2961,8 +2961,6 @@ int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string
*lcnam
}
/* }}} */
-
-
static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function
*fbc) /* {{{ */
{
if (EG(assertions) >= 0) {
@@ -3011,6 +3009,10 @@ static int zend_compile_assert(znode *result, zend_ast_list *args,
zend_string *
int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args,
zend_function *fbc) /* {{{ */
{
+ if (fbc->internal_function.handler == ZEND_FN(display_disabled_function)) {
+ return FAILURE;
+ }
+
if (zend_string_equals_literal(lcname, "strlen")) {
return zend_compile_func_strlen(result, args);
} else if (zend_string_equals_literal(lcname, "is_null")) {
diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c
index 3cb11aa..ef62d99 100644
--- a/ext/opcache/Optimizer/pass1_5.c
+++ b/ext/opcache/Optimizer/pass1_5.c
@@ -462,7 +462,8 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
zend_string_release(lc_name);
} else if (Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("extension_loaded")-1
&&
!memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)),
- "extension_loaded", sizeof("extension_loaded")-1)) {
+ "extension_loaded", sizeof("extension_loaded")-1) &&
+ !zend_optimizer_is_disabled_func("extension_loaded",
sizeof("extension_loaded") - 1)) {
zval t;
zend_string *lc_name = zend_string_tolower(
Z_STR(ZEND_OP1_LITERAL(send1_opline)));
@@ -494,7 +495,8 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
}
} else if (Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("defined")-1 &&
!memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)),
- "defined", sizeof("defined")-1)) {
+ "defined", sizeof("defined")-1) &&
+ !zend_optimizer_is_disabled_func("defined", sizeof("defined") - 1)) {
zval t;
if (zend_optimizer_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(send1_opline)), &t, 0))
{
@@ -511,7 +513,8 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
}
} else if (Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("constant")-1 &&
!memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)),
- "constant", sizeof("constant")-1)) {
+ "constant", sizeof("constant")-1) &&
+ !zend_optimizer_is_disabled_func("constant", sizeof("constant") - 1)) {
zval t;
if (zend_optimizer_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(send1_opline)), &t, 1))
{
@@ -526,7 +529,8 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
}
} else if ((CG(compiler_options) & ZEND_COMPILE_NO_BUILTIN_STRLEN) == 0 &&
Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("strlen") - 1 &&
- !memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)), "strlen",
sizeof("strlen") - 1)) {
+ !memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)), "strlen",
sizeof("strlen") - 1) &&
+ !zend_optimizer_is_disabled_func("strlen", sizeof("strlen") - 1)) {
zval t;
ZVAL_LONG(&t, Z_STRLEN(ZEND_OP1_LITERAL(send1_opline)));
@@ -541,7 +545,8 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
/* dirname(IS_CONST/IS_STRING) -> IS_CONST/IS_STRING */
} else if (Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("dirname")-1 &&
!memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)),
- "dirname", sizeof("dirname")-1) &&
+ "dirname", sizeof("dirname") - 1) &&
+ !zend_optimizer_is_disabled_func("dirname", sizeof("dirname") - 1)
&&
IS_ABSOLUTE_PATH(Z_STRVAL(ZEND_OP1_LITERAL(send1_opline)),
Z_STRLEN(ZEND_OP1_LITERAL(send1_opline)))) {
zend_string *dirname = zend_string_init(Z_STRVAL(ZEND_OP1_LITERAL(send1_opline)),
Z_STRLEN(ZEND_OP1_LITERAL(send1_opline)), 0);
dirname->len = zend_dirname(dirname->val, dirname->len);
diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c
index de45bf0..90aff7e 100644
--- a/ext/opcache/Optimizer/zend_optimizer.c
+++ b/ext/opcache/Optimizer/zend_optimizer.c
@@ -111,6 +111,13 @@ int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv)
return i;
}
+int zend_optimizer_is_disabled_func(const char *name, size_t len) {
+ zend_function *fbc = (zend_function *)zend_hash_str_find_ptr(EG(function_table), name, len);
+
+ return (fbc->type == ZEND_INTERNAL_FUNCTION &&
+ fbc->internal_function.handler == ZEND_FN(display_disabled_function));
+}
+
void zend_optimizer_update_op1_const(zend_op_array *op_array,
zend_op *opline,
zval *val)
diff --git a/ext/opcache/Optimizer/zend_optimizer_internal.h
b/ext/opcache/Optimizer/zend_optimizer_internal.h
index 05e1e09..c2f97ff 100644
--- a/ext/opcache/Optimizer/zend_optimizer_internal.h
+++ b/ext/opcache/Optimizer/zend_optimizer_internal.h
@@ -135,5 +135,6 @@ void optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx);
void optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *ctx);
void zend_optimizer_nop_removal(zend_op_array *op_array);
void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx);
+int zend_optimizer_is_disabled_func(const char *name, size_t len);
#endif