Skip to content

Commit 2d4d7aa

Browse files
authored
Update DangerousUseOfExceptionBlocks.ql
1 parent 75244ef commit 2d4d7aa

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-476/DangerousUseOfExceptionBlocks.ql

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,29 @@ predicate pointerDereference(CatchAnyBlock cb, Variable vr, Variable vro) {
115115
/** Holds if `vro` may be released in the `catch`. */
116116
pragma[inline]
117117
predicate newThrowDelete(CatchAnyBlock cb, Variable vro) {
118-
exists(Expr e0, AssignExpr ase, NewOrNewArrayExpr nae |
118+
exists(Expr e0, AssignExpr ase, NewOrNewArrayExpr nae |
119119
ase = vro.getAnAccess().getEnclosingStmt().(ExprStmt).getExpr().(AssignExpr) and
120120
nae = ase.getRValue().(NewOrNewArrayExpr) and
121121
not nae.getAChild*().toString() = "nothrow" and
122-
(
123-
e0 = nae or
124-
e0 = nae.getEnclosingFunction().getACallToThisFunction()
125-
) and
126-
vro = ase.getLValue().(VariableAccess).getTarget() and
127-
e0.getEnclosingStmt().getParentStmt*() = cb.getTryStmt().getStmt() and
122+
(
123+
e0 = nae or
124+
e0 = nae.getEnclosingFunction().getACallToThisFunction()
125+
) and
126+
vro = ase.getLValue().(VariableAccess).getTarget() and
127+
e0.getEnclosingStmt().getParentStmt*() = cb.getTryStmt().getStmt() and
128128
not exists(AssignExpr ase1 |
129129
vro = ase1.getLValue().(VariableAccess).getTarget() and
130130
ase1.getRValue().getValue() = "0" and
131131
ase1.getASuccessor*() = e0
132132
)
133133
) and
134-
not exists(Initializer it |
134+
not exists(Initializer it |
135135
vro.getInitializer() = it and
136-
it.getExpr().getValue() = "0"
136+
it.getExpr().getValue() = "0"
137137
) and
138-
not exists(ConstructorFieldInit ci |
139-
vro = ci.getTarget()
140-
)
138+
not exists(ConstructorFieldInit ci | vro = ci.getTarget())
141139
}
140+
142141
from CatchAnyBlock cb, string msg
143142
where
144143
exists(Variable vr, Variable vro, Expr exp |
@@ -185,14 +184,16 @@ where
185184
exists(Variable vro, Expr exp |
186185
exp.getEnclosingStmt().getParentStmt*() = cb and
187186
exists(VariableAccess va |
188-
(
189-
va = exp.(DeleteArrayExpr).getExpr().(VariableAccess) or
190-
va = exp.(DeleteExpr).getExpr().(VariableAccess)
191-
) and
192-
va.getEnclosingStmt() = exp.getEnclosingStmt() and
193-
vro = va.getTarget()
187+
(
188+
va = exp.(DeleteArrayExpr).getExpr().(VariableAccess) or
189+
va = exp.(DeleteExpr).getExpr().(VariableAccess)
190+
) and
191+
va.getEnclosingStmt() = exp.getEnclosingStmt() and
192+
vro = va.getTarget()
194193
) and
195-
newThrowDelete(cb,vro) and
196-
msg = "If the allocation in the try block fails, then an unallocated pointer "+vro.getName()+" will be freed in the catch block."
194+
newThrowDelete(cb, vro) and
195+
msg =
196+
"If the allocation in the try block fails, then an unallocated pointer " + vro.getName() +
197+
" will be freed in the catch block."
197198
)
198199
select cb, msg

0 commit comments

Comments
 (0)