Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e7bd9e

Browse files
committed
CPP: Queries: Similar dataflow simplification in OverflowCalculated.ql to that made recently in NoSpaceForZeroTerminator.ql.
1 parent 1fa3030 commit 1e7bd9e

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

cpp/ql/src/Critical/OverflowCalculated.ql

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,21 @@
1111
*/
1212

1313
import cpp
14+
import semmle.code.cpp.dataflow.DataFlow
1415

1516
class MallocCall extends FunctionCall {
1617
MallocCall() { this.getTarget().hasGlobalOrStdName("malloc") }
1718

1819
Expr getAllocatedSize() {
19-
if this.getArgument(0) instanceof VariableAccess
20-
then
21-
exists(LocalScopeVariable v, ControlFlowNode def |
22-
definitionUsePair(v, def, this.getArgument(0)) and
23-
exprDefinition(v, def, result)
24-
)
25-
else result = this.getArgument(0)
20+
result = this.getArgument(0)
2621
}
2722
}
2823

2924
predicate spaceProblem(FunctionCall append, string msg) {
3025
exists(MallocCall malloc, StrlenCall strlen, AddExpr add, FunctionCall insert, Variable buffer |
3126
add.getAChild() = strlen and
3227
exists(add.getAChild().getValue()) and
33-
malloc.getAllocatedSize() = add and
28+
DataFlow::localExprFlow(add, malloc.getAllocatedSize()) and
3429
buffer.getAnAccess() = strlen.getStringExpr() and
3530
(
3631
insert.getTarget().hasGlobalOrStdName("strcpy") or

0 commit comments

Comments
 (0)