-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAllocaInLoop.ql
More file actions
38 lines (34 loc) · 1.02 KB
/
AllocaInLoop.ql
File metadata and controls
38 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @name Call to alloca in a loop
* @description Using alloca in a loop can lead to a stack overflow
* @kind problem
* @problem.severity warning
* @precision high
* @id cpp/alloca-in-loop
* @tags reliability
* correctness
* security
* external/cwe/cwe-770
*/
import cpp
Loop getAnEnclosingLoopOfExpr(Expr e) {
result = e.getEnclosingStmt().getParent*() or
result = getAnEnclosingLoopOfStmt(e.getEnclosingStmt())
}
Loop getAnEnclosingLoopOfStmt(Stmt s) {
result = s.getParent*() or
result = getAnEnclosingLoopOfExpr(s.getParent*())
}
from Loop l, FunctionCall fc
where
getAnEnclosingLoopOfExpr(fc) = l and
(
fc.getTarget().getName() = "__builtin_alloca"
or
(
(fc.getTarget().getName() = "_alloca" or fc.getTarget().getName() = "_malloca") and
fc.getTarget().getADeclarationEntry().getFile().getBaseName() = "malloc.h"
)
) and
not l.(DoStmt).getCondition().getValue() = "0"
select fc, "Stack allocation is inside a $@ and could lead to stack overflow.", l, l.toString()