-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
658 changed files
with
82 additions
and
183,714 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name = "Possible Infinite Loop"; | ||
description = "Loops on files that can't be open results in infinite loop. | ||
<?php | ||
$file = fopen('/path/to/file.txt', 'r'); | ||
// when fopen() fails, the next loops is infinite | ||
// fgets() will always return false, and while will always be true. | ||
while($line = fgets($file) != '') { | ||
doSomething(); | ||
} | ||
?> | ||
"; | ||
clearphp = ""; | ||
exakatSince = "1.1.5"; |
61 changes: 61 additions & 0 deletions
61
library/Exakat/Analyzer/Structures/PossibleInfiniteLoop.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/* | ||
* Copyright 2012-2018 Damien Seguy – Exakat Ltd <contact(at)exakat.io> | ||
* This file is part of Exakat. | ||
* | ||
* Exakat is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Exakat is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Exakat. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <http://exakat.io/>. | ||
* | ||
*/ | ||
|
||
namespace Exakat\Analyzer\Structures; | ||
|
||
use Exakat\Analyzer\Analyzer; | ||
|
||
class PossibleInfiniteLoop extends Analyzer { | ||
public function analyze() { | ||
$readFunctions = array('\fgets', '\fgetc', '\fgetss', '\fgetcsv'); | ||
|
||
//while($line = fgets($fp1) != 'a') {} | ||
$this->atomIs(array('While', 'Dowhile')) | ||
->outIs('CONDITION') | ||
->outIsIE(array('LEFT', 'RIGHT')) // outIsIE goes directly to the comparison operands | ||
->functioncallIs($readFunctions) | ||
->inIs(array('LEFT', 'RIGHT')) | ||
->atomIs('Comparison') | ||
->codeIs('!=') | ||
->outIs(array('LEFT', 'RIGHT')) | ||
->isLiteral() | ||
->is('boolean', true) | ||
->back('first'); | ||
$this->prepareQuery(); | ||
|
||
//while($line = fgets($fp1) != 'a') {} | ||
$this->atomIs('While') | ||
->outIs('CONDITION') | ||
->outIsIE(array('LEFT', 'RIGHT')) // outIsIE goes directly to the comparison operands | ||
->functioncallIs($readFunctions) | ||
->inIs(array('LEFT', 'RIGHT')) | ||
->atomIs('Comparison') | ||
->codeIs('!=') | ||
->outIs(array('LEFT', 'RIGHT')) | ||
->isLiteral() | ||
->is('boolean', true) | ||
->back('first'); | ||
$this->prepareQuery(); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.