Skip to content

Commit 2212c47

Browse files
committed
CPP: Use dataflow more consistently.
1 parent e6ea705 commit 2212c47

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

cpp/ql/src/Security/CWE/CWE-131/NoSpaceForZeroTerminator.ql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@ class MallocCall extends FunctionCall {
2222
MallocCall() { this.getTarget().hasGlobalOrStdName("malloc") }
2323

2424
Expr getAllocatedSize() {
25-
if this.getArgument(0) instanceof VariableAccess
26-
then
27-
exists(LocalScopeVariable v, ControlFlowNode def |
28-
definitionUsePair(v, def, this.getArgument(0)) and
29-
exprDefinition(v, def, result)
30-
)
31-
else result = this.getArgument(0)
25+
result = this.getArgument(0)
3226
}
3327
}
3428

3529
predicate terminationProblem(MallocCall malloc, string msg) {
3630
// malloc(strlen(...))
37-
malloc.getAllocatedSize() instanceof StrlenCall and
31+
exists(StrlenCall strlen |
32+
DataFlow::localExprFlow(strlen, malloc.getAllocatedSize())
33+
) and
3834
// flows into a null-terminated string function
3935
exists(ArrayFunction af, FunctionCall fc, int arg |
4036
DataFlow::localExprFlow(malloc, fc.getArgument(arg)) and

0 commit comments

Comments
 (0)