Skip to content

Commit b7df18b

Browse files
authored
Update AccessOfMemoryLocationAfterEndOfBufferUsingStrlen.ql
1 parent 92a5a2a commit b7df18b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-788/AccessOfMemoryLocationAfterEndOfBufferUsingStrlen.ql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@
1313

1414
import cpp
1515
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
16+
import semmle.code.cpp.dataflow.DataFlow
1617

1718
from StrlenCall fc, AssignExpr expr, ArrayExpr exprarr
1819
where
1920
exprarr = expr.getLValue() and
2021
expr.getRValue().getValue().toInt() = 0 and
21-
exprarr.getArrayOffset() = fc and
22+
globalValueNumber(exprarr.getArrayOffset()) = globalValueNumber(fc) and
23+
not exists(Expr exptmp |
24+
(
25+
DataFlow::localExprFlow(fc, exptmp) or
26+
exptmp.getAChild*() = fc.getArgument(0).(VariableAccess).getTarget().getAnAccess()
27+
) and
28+
dominates(exptmp, expr) and
29+
postDominates(exptmp, fc) and
30+
not exptmp.getEnclosingStmt() = fc.getEnclosingStmt() and
31+
not exptmp.getEnclosingStmt() = expr.getEnclosingStmt()
32+
) and
2233
globalValueNumber(fc.getArgument(0)) = globalValueNumber(exprarr.getArrayBase())
2334
select expr, "potential unsafe or redundant assignment."

0 commit comments

Comments
 (0)