Skip to content

Commit c15f3da

Browse files
committed
update style and php-cfg
1 parent 5b424d8 commit c15f3da

File tree

100 files changed

+7628
-6551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+7628
-6551
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- "8.1"
1616
- "8.2"
1717
- "8.3"
18+
- "8.4"
1819
steps:
1920
- name: "Checkout"
2021
uses: "actions/checkout@v2"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"require": {
1212
"php": ">=7.4",
13-
"ircmaxell/php-cfg": "^0.7.0",
13+
"ircmaxell/php-cfg": "^0.8.0",
1414
"symfony/yaml": "^5.4.17",
1515
"symfony/console": "^5.4.17",
1616
"myclabs/deep-copy": "^1.11.0",

package/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"require": {
1212
"php": ">=7.4",
13-
"ircmaxell/php-cfg": "^0.7.0",
13+
"ircmaxell/php-cfg": "^0.8.0",
1414
"symfony/yaml": "^5.4.17",
1515
"symfony/console": "^5.4.17",
1616
"bartlett/sarif-php-sdk": "^2.0"

package/src/progpilot/Analysis/AssertionAnalysis.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
namespace progpilot\Analysis;
1212

13-
use progpilot\Objects\MyDefinition;
14-
1513
class AssertionAnalysis
1614
{
1715
public static function checkDefIsAssert($myBlock, $def)

package/src/progpilot/Analysis/CustomAnalysis.php

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use progpilot\Representations\NodeCG;
1616
use progpilot\Inputs\MyCustomRule;
1717
use progpilot\Objects\MyDefinition;
18-
use progpilot\Objects\MyClass;
19-
use progpilot\Code\MyInstruction;
2018
use progpilot\Utils;
2119
use progpilot\Helpers\Analysis as HelpersAnalysis;
2220

@@ -26,13 +24,15 @@ public static function disclosureOfInformation($context, $defs, $defassign)
2624
{
2725
$customRules = $context->inputs->getCustomRules();
2826
foreach ($customRules as $customRule) {
29-
if ($customRule->getType() === MyCustomRule::TYPE_VARIABLE
30-
&& $customRule->getAction() === "ASSIGNMENT_DISCLOSE_HIGH_VALUE") {
27+
if (
28+
$customRule->getType() === MyCustomRule::TYPE_VARIABLE
29+
&& $customRule->getAction() === "ASSIGNMENT_DISCLOSE_HIGH_VALUE"
30+
) {
3131
$result = HelpersAnalysis::checkIfDefEqualDefRule($context, $defs, $customRule, $defassign);
32-
32+
3333
if ($result) {
3434
$hashedValue = $defassign->getLine();
35-
$hashedValue.= "-".$customRule->getAction()."-".$defassign->getSourceMyFile()->fileName;
35+
$hashedValue .= "-" . $customRule->getAction() . "-" . $defassign->getSourceMyFile()->fileName;
3636
$idVuln = hash("sha256", $hashedValue);
3737

3838
if (is_null($context->inputs->getFalsePositiveById($idVuln))) {
@@ -50,17 +50,19 @@ public static function disclosureOfInformation($context, $defs, $defassign)
5050
}
5151
}
5252
}
53-
53+
5454
return null;
5555
}
56-
56+
5757
public static function defineObject($context, $instruction, $myFuncorDef, $myClassFound, $virtualReturnDef)
5858
{
5959
$customRules = $context->inputs->getCustomRules();
6060
foreach ($customRules as $customRule) {
61-
if ($customRule->getType() === MyCustomRule::TYPE_VARIABLE
61+
if (
62+
$customRule->getType() === MyCustomRule::TYPE_VARIABLE
6263
&& $customRule->getAction() === "DEFINE_OBJECT"
63-
&& !is_null($customRule->getExtra())) {
64+
&& !is_null($customRule->getExtra())
65+
) {
6466
$result = HelpersAnalysis::checkIfDefEqualDefRule(
6567
$context,
6668
null,
@@ -79,10 +81,10 @@ public static function defineObject($context, $instruction, $myFuncorDef, $myCla
7981
}
8082
}
8183
}
82-
84+
8385
return null;
8486
}
85-
87+
8688
public static function returnObjectCreateObject($context, $customRule, $myFuncorDef, $virtualReturnDef)
8789
{
8890
$myFakeInstance = null;
@@ -103,14 +105,16 @@ public static function returnObjectCreateObject($context, $customRule, $myFuncor
103105
return $myFakeInstance;
104106
}
105107
}
106-
108+
107109
public static function returnObject($context, $myFuncorDef, $myClass, $instruction, $virtualReturnDef)
108110
{
109111
$customRules = $context->inputs->getCustomRules();
110112
foreach ($customRules as $customRule) {
111-
if ($customRule->getType() === MyCustomRule::TYPE_FUNCTION
112-
&& $customRule->getAction() === "DEFINE_OBJECT"
113-
&& !is_null($customRule->getExtra())) {
113+
if (
114+
$customRule->getType() === MyCustomRule::TYPE_FUNCTION
115+
&& $customRule->getAction() === "DEFINE_OBJECT"
116+
&& !is_null($customRule->getExtra())
117+
) {
114118
$result = HelpersAnalysis::checkIfDefEqualDefRule(
115119
$context,
116120
null,
@@ -128,19 +132,21 @@ public static function returnObject($context, $myFuncorDef, $myClass, $instructi
128132
}
129133
}
130134
}
131-
135+
132136
return null;
133137
}
134138

135139
public static function mustVerifyDefinition($context, $instruction, $myFunc, $myClass = null)
136140
{
137141
$customRules = $context->inputs->getCustomRules();
138142
foreach ($customRules as $customRule) {
139-
if ($customRule->getType() === MyCustomRule::TYPE_FUNCTION
143+
if (
144+
$customRule->getType() === MyCustomRule::TYPE_FUNCTION
140145
&& ($customRule->getAction() === "MUST_VERIFY_DEFINITION"
141-
|| $customRule->getAction() === "MUST_NOT_VERIFY_DEFINITION")) {
146+
|| $customRule->getAction() === "MUST_NOT_VERIFY_DEFINITION")
147+
) {
142148
$functionDefinition = $customRule->getDefinition();
143-
149+
144150
if (!is_null($functionDefinition)) {
145151
$result = HelpersAnalysis::checkIfFuncEqualMySpecify(
146152
$context,
@@ -149,13 +155,15 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
149155
$myClass
150156
);
151157
if ($result) {
152-
if ($myFunc->getNbParams() < $functionDefinition->getMinNbArgs()
153-
|| $myFunc->getNbParams() > $functionDefinition->getMaxNbArgs()) {
158+
if (
159+
$myFunc->getNbParams() < $functionDefinition->getMinNbArgs()
160+
|| $myFunc->getNbParams() > $functionDefinition->getMaxNbArgs()
161+
) {
154162
$isValid = true;
155163
} else {
156164
$isValid = false;
157165
$params = $functionDefinition->getParameters();
158-
166+
159167
// if one parameter is not valid all the rule is not valid
160168
foreach ($params as $param) {
161169
$isValid = false;
@@ -173,17 +181,19 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
173181
$isValid = $validbydefault;
174182
break;
175183
}
176-
184+
177185
$defArg = $instruction->getProperty("argdef$idParam");
178-
186+
179187
foreach ($valuesParameter as $valueParameter) {
180188
$defLastKnownValues = [];
181189

182-
if (isset($valueParameter->is_array)
190+
if (
191+
isset($valueParameter->is_array)
183192
&& $valueParameter->is_array === true
184-
&& isset($valueParameter->array_index)) {
193+
&& isset($valueParameter->array_index)
194+
) {
185195
$arrayfound = false;
186-
196+
187197
if ($defArg->getCurrentState()->isType(MyDefinition::TYPE_ARRAY)) {
188198
foreach ($defArg->getCurrentState()->getArrayIndexes() as $arrayIndex) {
189199
if ($arrayIndex->index === $valueParameter->array_index) {
@@ -195,15 +205,15 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
195205
}
196206
}
197207
}
198-
208+
199209
if (!$arrayfound) {
200210
$isValid = $validbydefault;
201211
break 2;
202212
}
203213
} else {
204214
$defLastKnownValues = $defArg->getCurrentState()->getLastKnownValues();
205215
}
206-
216+
207217
if (count($defLastKnownValues) === 0) {
208218
$isValid = false;
209219
}
@@ -213,9 +223,10 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
213223
foreach ($defLastKnownValues as $lastKnownValue) {
214224
// if it's valid we continue
215225
if (($valueParameter->value === $lastKnownValue
216-
&& !$isParameterNotEquals)
226+
&& !$isParameterNotEquals)
217227
|| ($valueParameter->value !== $lastKnownValue
218-
&& $isParameterNotEquals)) {
228+
&& $isParameterNotEquals)
229+
) {
219230
$validForAllValues = true;
220231
} else {
221232
// it's not valid we can break
@@ -253,8 +264,10 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
253264
// * it can be enough (if sufficient) to valid the rule (no issue)
254265

255266
// one parameter is not valid and required
256-
if (!$isValid
257-
&& $isParameterFixed) {
267+
if (
268+
!$isValid
269+
&& $isParameterFixed
270+
) {
258271
$isValid = true;
259272
break;
260273
}
@@ -264,15 +277,19 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
264277
}
265278

266279
// one parameter is valid and enough
267-
if ($isValid
268-
&& $isParameterSufficient) {
280+
if (
281+
$isValid
282+
&& $isParameterSufficient
283+
) {
269284
$isValid = true;
270285
break;
271286
}
272287

273288
// one parameter is not valid but should not fail and continue with other params
274-
if (!$isValid
275-
&& !$isParameterFailIfNotVerifed) {
289+
if (
290+
!$isValid
291+
&& !$isParameterFailIfNotVerifed
292+
) {
276293
$isValid = true;
277294
}
278295

@@ -283,12 +300,12 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
283300
}
284301
}
285302
}
286-
303+
287304
if (!$isValid) {
288305
$hashedValue = $myFunc->getLine();
289-
$hashedValue.= "-".$customRule->getAction()."-".$myFunc->getSourceMyFile()->fileName;
306+
$hashedValue .= "-" . $customRule->getAction() . "-" . $myFunc->getSourceMyFile()->fileName;
290307
$idVuln = hash("sha256", $hashedValue);
291-
308+
292309
if (is_null($context->inputs->getFalsePositiveById($idVuln))) {
293310
$temp["vuln_rule"] = Utils::encodeCharacters($customRule->getAction());
294311
$temp["vuln_name"] = Utils::encodeCharacters($customRule->getAttack());
@@ -314,8 +331,10 @@ public static function mustVerifyCallFlow($context, $callgraph)
314331
$rulesVerifyCallFlow = [];
315332
$customRules = $context->inputs->getCustomRules();
316333
foreach ($customRules as $customRule) {
317-
if ($customRule->getType() === MyCustomRule::TYPE_SEQUENCE
318-
&& $customRule->getAction() === "MUST_VERIFY_CALL_FLOW") {
334+
if (
335+
$customRule->getType() === MyCustomRule::TYPE_SEQUENCE
336+
&& $customRule->getAction() === "MUST_VERIFY_CALL_FLOW"
337+
) {
319338
$sequence = $customRule->getSequence();
320339

321340
$customRule->setCurrentOrderNumber(0);

package/src/progpilot/Analysis/FuncAnalysis.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010

1111
namespace progpilot\Analysis;
1212

13-
use progpilot\Objects\MyFunction;
1413
use progpilot\Objects\MyDefinition;
15-
use progpilot\Code\Opcodes;
1614
use progpilot\Code\MyInstruction;
1715

18-
use progpilot\Helpers\Analysis as HelpersAnalysis;
19-
2016
class FuncAnalysis
2117
{
2218
public static function funccallAfter(
@@ -34,7 +30,7 @@ public static function funccallAfter(
3430
$context->getCurrentMyFile(),
3531
$myFuncCall->getLine(),
3632
$myFuncCall->getColumn(),
37-
$myFuncCall->getName()."_return"
33+
$myFuncCall->getName() . "_return"
3834
);
3935

4036
$opInformation["chained_results"][] = $myFuncReturn;
@@ -90,7 +86,7 @@ public static function funccallAfter(
9086
}
9187
}
9288
}
93-
89+
9490
$context->getCurrentFunc()->storeOpInformation($resultid, $opInformation);
9591
}
9692

@@ -105,11 +101,11 @@ public static function funccallBefore($myFunc, $instruction)
105101

106102
$param->setParamToArg($defArg);
107103
$defArg->setArgToParam($param);
108-
104+
109105
$state = $defArg->createState();
110106
$defArg->assignStateToBlockId($state->getId(), $param->getBlockId());
111107

112-
$nbParams ++;
108+
$nbParams++;
113109
}
114110
}
115111
}

0 commit comments

Comments
 (0)