Skip to content

Commit 4f0e32f

Browse files
committed
BadFunctions/EasyRFI: bug fix - fix detecting of start/end of the statement [2]
PHPCS can be run from within an IDE during live coding. Similarly PHPCS can be run over files containing parse errors. With that in mind, it is best practice to bow out in those cases. Parse error detection should catch those errors. That is not the responsibility of this sniff.
1 parent e0a3764 commit 4f0e32f

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

Security/Sniffs/BadFunctions/EasyRFISniff.php

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function register() {
3939
*/
4040
public function process(File $phpcsFile, $stackPtr) {
4141
$closer = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
42+
if ($closer === false) {
43+
// Live coding or parse error.
44+
return;
45+
}
4246

4347
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
4448
$tokens = $phpcsFile->getTokens();

Security/Tests/BadFunctions/EasyRFIUnitTest.0.inc

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ include arg(2) . drupal_get_query_parameters()['param'];
1515

1616
// Prevent false positives on safe $_SERVER variables.
1717
include $_SERVER['DOCUMENT_ROOT'] . '/filename.php';
18+
19+
// Intentional parse error. This should be the last test in the file.
20+
require_once

Security/Tests/BadFunctions/EasyRFIUnitTest.1.inc

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ include arg(2) . drupal_get_query_parameters()['param']; // Warning x 2.
1515

1616
// Prevent false positives on safe $_SERVER variables.
1717
include $_SERVER['DOCUMENT_ROOT'] . '/filename.php'; // Error.
18+
19+
// Intentional parse error. This should be the last test in the file.
20+
require $_GET['path']

Security/Tests/BadFunctions/EasyRFIUnitTest.Drupal7.1.inc

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ include getenv('PATHTOFILE'); // Error.
1212
// Drupal 7.
1313
include ( 'path/to/' . $form['filename'] ); // Error.
1414
include arg(2) . drupal_get_query_parameters()['param']; // Error x 2.
15+
16+
// Intentional parse error. This should be the last test in the file.
17+
include_once ( $_GET['path']

0 commit comments

Comments
 (0)