Skip to content

Commit 8dc9eae

Browse files
committed
BadFunctions/Backticks: error message line precision
A backtick-shell command can be spread out over several lines. This minor change make it so the error/warning will be reported on the line containing the offending variable, not the line containing the open-backtick, as these may not be the same.
1 parent d7a55ea commit 8dc9eae

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Security/Sniffs/BadFunctions/BackticksSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public function process(File $phpcsFile, $stackPtr) {
3737
while (($s = $phpcsFile->findNext(T_VARIABLE, ($s + 1), $closer)) !== false) {
3838
$msg = 'System execution with backticks detected with dynamic parameter';
3939
if ($utils::is_token_user_input($tokens[$s])) {
40-
$phpcsFile->addError($msg . ' directly from user input', $stackPtr, 'ErrSystemExec');
40+
$phpcsFile->addError($msg . ' directly from user input', $s, 'ErrSystemExec');
4141
} else {
42-
$phpcsFile->addWarning($msg, $stackPtr, 'WarnSystemExec');
42+
$phpcsFile->addWarning($msg, $s, 'WarnSystemExec');
4343
}
4444
}
4545

Security/Tests/BadFunctions/BackticksUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ $output = `git blame --date=short "$filename"`; // Warning.
1212

1313
$output = `git blame --date=$_POST['key'] "$filename"`; // Warning + error.
1414

15+
$output = `git blame
16+
--date=$_POST['key'] // Error.
17+
"$filename"`; // Warning.
18+
1519
// Incomplete command. Ignore.
1620
// Intentional parse error. This should be the last test in the file.
1721
$output = `ls

Security/Tests/BadFunctions/BackticksUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function getErrorList($testFile = '')
2727
return [
2828
9 => 1,
2929
13 => 1,
30+
16 => 1,
3031
];
3132

3233
case 'BackticksUnitTest.Drupal7.inc':
@@ -72,6 +73,7 @@ public function getWarningList($testFile = '')
7273
8 => 1,
7374
11 => 1,
7475
13 => 1,
76+
17 => 1,
7577
];
7678

7779
case 'BackticksUnitTest.Drupal7.inc':

0 commit comments

Comments
 (0)