我的PHP版本是7.2.9-1。在下面的练习中,行assert
上有一个代码注入:
extract($_POST);
function goAway() {
error_log("Hacking attempt.");
header('Location: /error/');
}
if (!isset($pi) || !is_numeric($pi)) {
goAway();
}
if (!assert("(int)$pi == 3")) {
echo "This is not pi.";
} else {
echo "This might be pi.";
}
assert()操作计算PHP代码,它包含用户输入。但是,我使用的是pi=phpinfo()
,服务器不会phpinfo()
,而是只输出This might be pi.
。有没有人能解释一下?
发布于 2018-09-05 07:23:57
PHP手册中的:
断言不应用于正常的运行时操作,如输入参数检查。根据经验,如果断言检查未激活,您的代码应该始终能够正确工作。
在您的PHP配置中可能只是禁用了断言。检查您的php.ini
文件或assert_options()
。
此外,根据您提供的代码示例,这是,而不是assert
的用途。
https://stackoverflow.com/questions/52174872
复制相似问题