Skip to content

Commit 454f175

Browse files
committed
BadFunctions/EasyRFI: use the build-in PHPCS functionality
The PHPCS [`addError()`](https://pear.php.net/package/PHP_CodeSniffer/docs/3.5.4/apidoc/PHP_CodeSniffer/File.html#methodaddError) and [`addWarning()`](https://pear.php.net/package/PHP_CodeSniffer/docs/3.5.4/apidoc/PHP_CodeSniffer/File.html#methodaddWarning) functions have a build-in string replacement `sprintf()`-like functionality, so let's use it.
1 parent 53be140 commit 454f175

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Security/Sniffs/BadFunctions/EasyRFISniff.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ public function process(File $phpcsFile, $stackPtr) {
5050
}
5151
while ($s) {
5252
$s = $phpcsFile->findNext($this->search, $s + 1, $closer, true);
53+
54+
$data = array(
55+
$tokens[$s]['content'],
56+
$tokens[$stackPtr]['content'],
57+
);
58+
5359
if ($s && $utils::is_token_user_input($tokens[$s])) {
5460
if (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') || !$utils::is_token_false_positive($tokens[$s], $tokens[$s+2])) {
55-
$phpcsFile->addError('Easy RFI detected because of direct user input with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'ErrEasyRFI');
61+
$phpcsFile->addError('Easy RFI detected because of direct user input with %s on %s', $s, 'ErrEasyRFI', $data);
5662
}
5763
} elseif ($s && \PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') && $tokens[$s]['content'] != '.') {
58-
$phpcsFile->addWarning('Possible RFI detected with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'WarnEasyRFI');
64+
$phpcsFile->addWarning('Possible RFI detected with %s on %s', $s, 'WarnEasyRFI', $data);
5965
}
6066
}
6167
}

0 commit comments

Comments
 (0)