Skip to content

Promote warning to error in zend_forbid_dynamic_call() #4592

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

Closed
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
12 changes: 9 additions & 3 deletions Zend/tests/bug71221.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ Bug #71221 (Null pointer deref (segfault) in get_defined_vars via ob_start)
--FILE--
<?php
ob_start("get_defined_vars");
ob_end_clean();
try {
ob_end_clean();
} catch (\Error $e) {
echo $e->getMessage();
}
?>
okey

OKAY
--EXPECT--
okey
Cannot call get_defined_vars() dynamically
OKAY
12 changes: 7 additions & 5 deletions Zend/tests/bug72107.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ set_error_handler('func_get_args');
function test($a) {
echo $undef;
}
test(1);
try {
test(1);
} catch (\Error $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
Warning: Cannot call func_get_args() dynamically in %s on line %d

Notice: Undefined variable: undef in %s on line %d
--EXPECT--
Cannot call func_get_args() dynamically
37 changes: 22 additions & 15 deletions Zend/tests/dynamic_call_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@ Dynamic calls to scope introspection functions are forbidden
function test_calls($func) {
$i = 1;

array_map($func, [['i' => new stdClass]]);
var_dump($i);
try {
array_map($func, [['i' => new stdClass]]);
var_dump($i);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

$func(['i' => new stdClass]);
var_dump($i);
try {
$func(['i' => new stdClass]);
var_dump($i);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

call_user_func($func, ['i' => new stdClass]);
var_dump($i);
try {
call_user_func($func, ['i' => new stdClass]);
var_dump($i);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
test_calls('extract');

?>
--EXPECTF--
Warning: Cannot call extract() dynamically in %s on line %d
int(1)

Warning: Cannot call extract() dynamically in %s on line %d
int(1)

Warning: Cannot call extract() dynamically in %s on line %d
int(1)
--EXPECT--
Cannot call extract() dynamically
Cannot call extract() dynamically
Cannot call extract() dynamically
76 changes: 48 additions & 28 deletions Zend/tests/dynamic_call_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,56 @@ Dynamic calls to scope introspection functions are forbidden (function variation
--FILE--
<?php
function test() {
$func = 'extract';
$func(['a' => 'b']);

$func = 'compact';
$func(['a']);

$func = 'get_defined_vars';
$func();

$func = 'func_get_args';
$func();

$func = 'func_get_arg';
$func(1);

$func = 'func_num_args';
$func();
try {
$func = 'extract';
$func(['a' => 'b']);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

try {
$func = 'compact';
$func(['a']);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

try {
$func = 'get_defined_vars';
$func();
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

try {
$func = 'func_get_args';
$func();
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

try {
$func = 'func_get_arg';
$func(1);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

try {
$func = 'func_num_args';
$func();
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
test();

?>
--EXPECTF--
Warning: Cannot call extract() dynamically in %s on line %d

Warning: Cannot call compact() dynamically in %s on line %d

Warning: Cannot call get_defined_vars() dynamically in %s on line %d

Warning: Cannot call func_get_args() dynamically in %s on line %d

Warning: Cannot call func_get_arg() dynamically in %s on line %d

Warning: Cannot call func_num_args() dynamically in %s on line %d
--EXPECT--
Cannot call extract() dynamically
Cannot call compact() dynamically
Cannot call get_defined_vars() dynamically
Cannot call func_get_args() dynamically
Cannot call func_get_arg() dynamically
Cannot call func_num_args() dynamically
10 changes: 7 additions & 3 deletions Zend/tests/dynamic_call_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ Dynamic calls to scope introspection functions are forbidden (misoptimization)

function test() {
$i = 1;
array_map('extract', [['i' => new stdClass]]);
try {
array_map('extract', [['i' => new stdClass]]);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
$i += 1;
var_dump($i);
}
test();

?>
--EXPECTF--
Warning: Cannot call extract() dynamically in %s on line %d
--EXPECT--
Cannot call extract() dynamically
int(2)
10 changes: 7 additions & 3 deletions Zend/tests/dynamic_call_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ Don't optimize dynamic call to non-dynamic one if it drops the warning
<?php

function test() {
((string) 'extract')(['a' => 42]);
try {
((string) 'extract')(['a' => 42]);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
test();

?>
--EXPECTF--
Warning: Cannot call extract() dynamically in %s on line %d
--EXPECT--
Cannot call extract() dynamically
2 changes: 1 addition & 1 deletion Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ static zend_always_inline int zend_forbid_dynamic_call(const char *func_name)
ZEND_ASSERT(ex != NULL && ex->func != NULL);

if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) {
zend_error(E_WARNING, "Cannot call %s dynamically", func_name);
zend_throw_error(NULL, "Cannot call %s dynamically", func_name);
return FAILURE;
}

Expand Down
12 changes: 9 additions & 3 deletions ext/standard/tests/array/bug71220.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ Bug #71220 (Null pointer deref (segfault) in compact via ob_start)
--FILE--
<?php
ob_start("compact");
ob_end_clean();
try {
ob_end_clean();
} catch (\Error $e) {
echo $e->getMessage();
}
?>
okey

OKAY
--EXPECT--
okey
Cannot call compact() dynamically
OKAY