Skip to content

Commit c8f2937

Browse files
authored
Update DeclarationOfVariableWithUnnecessarilyWideScope.ql
1 parent 976ccda commit c8f2937

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-1126/DeclarationOfVariableWithUnnecessarilyWideScope.ql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class DangerousWhileLoop extends WhileStmt {
2727
not exp instanceof PointerFieldAccess and
2828
not exp instanceof ValueFieldAccess and
2929
exp.(VariableAccess).getTarget().getName() = dl.getName() and
30-
not exp.getParent*() instanceof CrementOperation and
31-
not exp.getParent*() instanceof Assignment and
3230
not exp.getParent*() instanceof FunctionCall
3331
}
3432

@@ -37,10 +35,10 @@ class DangerousWhileLoop extends WhileStmt {
3735
/** Holds when there are changes to the variables involved in the condition. */
3836
predicate isUseThisVariable() {
3937
exists(Variable v |
40-
exp.(VariableAccess).getTarget() = v and
38+
this.getCondition().getAChild*().(VariableAccess).getTarget() = v and
4139
(
4240
exists(Assignment aexp |
43-
aexp = this.getStmt().getAChild*() and
41+
this = aexp.getEnclosingStmt().getParentStmt*() and
4442
(
4543
aexp.getLValue().(ArrayExpr).getArrayBase().(VariableAccess).getTarget() = v
4644
or
@@ -49,7 +47,7 @@ class DangerousWhileLoop extends WhileStmt {
4947
)
5048
or
5149
exists(CrementOperation crm |
52-
crm = this.getStmt().getAChild*() and
50+
this = crm.getEnclosingStmt().getParentStmt*() and
5351
crm.getOperand().(VariableAccess).getTarget() = v
5452
)
5553
)
@@ -59,4 +57,4 @@ class DangerousWhileLoop extends WhileStmt {
5957

6058
from DangerousWhileLoop lp
6159
where not lp.isUseThisVariable()
62-
select lp.getDeclaration(), "A variable with this name is used in the loop condition."
60+
select lp.getDeclaration(), "A variable with this name is used in the $@ condition.", lp, "loop"

0 commit comments

Comments
 (0)