Skip to content

Commit b7de370

Browse files
authored
Add files via upload
1 parent c1d125b commit b7de370

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-415/DoubleFree.ql

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,33 @@
1212

1313
import cpp
1414

15-
/**
16-
* The function allows `getASuccessor` to be called recursively.
17-
* This provides a stop in situations of possible influence on the pointer.
18-
*/
19-
ControlFlowNode recursASuccessor(FunctionCall fc, LocalScopeVariable v) {
20-
result = fc
21-
or
22-
exists(ControlFlowNode mid |
23-
mid = recursASuccessor(fc, v) and
24-
result = mid.getASuccessor() and
25-
not result = v.getAnAssignedValue() and
26-
not result.(AddressOfExpr).getOperand() = v.getAnAccess() and
27-
not (
28-
not result instanceof DeallocationExpr and
29-
result.(FunctionCall).getAnArgument().(VariableAccess).getTarget() = v
30-
) and
15+
from FunctionCall fc, FunctionCall fc2, LocalScopeVariable v
16+
where
17+
freeCall(fc, v.getAnAccess()) and
18+
freeCall(fc2, v.getAnAccess()) and
19+
fc != fc2 and
20+
fc.getASuccessor*() = fc2 and
21+
not exists(Expr exptmp |
22+
(exptmp = v.getAnAssignedValue() or exptmp.(AddressOfExpr).getOperand() = v.getAnAccess()) and
23+
exptmp = fc.getASuccessor*() and
24+
exptmp = fc2.getAPredecessor*()
25+
) and
26+
not exists(FunctionCall fctmp |
27+
not fctmp instanceof DeallocationExpr and
28+
fctmp = fc.getASuccessor*() and
29+
fctmp = fc2.getAPredecessor*() and
30+
fctmp.getAnArgument().(VariableAccess).getTarget() = v
31+
) and
32+
(
33+
fc.getTarget().hasGlobalOrStdName("realloc") and
3134
(
32-
fc.getTarget().hasGlobalOrStdName("realloc") and
33-
(
34-
not fc.getParent*() instanceof IfStmt and
35-
not result instanceof IfStmt
35+
not fc.getParent*() instanceof IfStmt and
36+
not exists(IfStmt iftmp |
37+
iftmp.getCondition().getAChild*().(VariableAccess).getTarget().getAnAssignedValue() = fc
3638
)
37-
or
38-
not fc.getTarget().hasGlobalOrStdName("realloc")
3939
)
40+
or
41+
not fc.getTarget().hasGlobalOrStdName("realloc")
4042
)
41-
}
42-
43-
from FunctionCall fc
44-
where
45-
exists(FunctionCall fc2, LocalScopeVariable v |
46-
freeCall(fc, v.getAnAccess()) and
47-
freeCall(fc2, v.getAnAccess()) and
48-
fc != fc2 and
49-
recursASuccessor(fc, v) = fc2
50-
)
51-
select fc.getArgument(0), "This pointer may be cleared again later."
43+
select fc2.getArgument(0),
44+
"This pointer may have already been cleared in the line " + fc.getLocation().getStartLine() + "."

0 commit comments

Comments
 (0)