mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Updated query to look for Microsoft-specific '_alloca' and '_malloca' entry points. Added sundry positive and negative test cases.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
* correctness
|
||||
* external/cwe/cwe-770
|
||||
*/
|
||||
|
||||
import cpp
|
||||
|
||||
Loop getAnEnclosingLoopOfExpr(Expr e) {
|
||||
@@ -21,7 +22,15 @@ Loop getAnEnclosingLoopOfStmt(Stmt s) {
|
||||
}
|
||||
|
||||
from Loop l, FunctionCall fc
|
||||
where getAnEnclosingLoopOfExpr(fc) = l
|
||||
and fc.getTarget().getName() = "__builtin_alloca"
|
||||
and not l.(DoStmt).getCondition().getValue() = "0"
|
||||
select fc, "Stack allocation is inside a $@ and could lead to overflow.", l, l.toString()
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user