Skip to content

Commit a6b5c5e

Browse files
committed
Accept true/false as the first parameter for assert()
1 parent 47d241a commit a6b5c5e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Security/Sniffs/BadFunctions/AssertsSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ public function process(File $phpcsFile, $stackPtr) {
3434
$closer = $tokens[$opener]['parenthesis_closer'];
3535
$s = $stackPtr + 1;
3636
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
37-
if ($s) {
37+
38+
// Accept true/false as the first parameter
39+
if (in_array(strtolower($tokens[$s]['content']), array('true', 'false'))) {
40+
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s + 1, $closer, true);
41+
}
42+
43+
if ($s) {
3844
$msg = 'Assert eval function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter';
3945
if ($utils::is_token_user_input($tokens[$s])) {
4046
$phpcsFile->addError($msg . ' directly from user input', $stackPtr, 'ErrFunctionHandling');

tests.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
`$_GET`;
2525
include($a);
2626
assert($a);
27+
assert(TRUE,$a);
2728
assert($_GET);
2829
exec($a);
2930
exec($_GET);

0 commit comments

Comments
 (0)