Skip to content

Commit 8163def

Browse files
committed
CPP: Alter the dataflow case.
1 parent 8ab830f commit 8163def

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cpp/ql/src/semmle/code/cpp/commons/Buffer.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ predicate memberMayBeVarSize(Class c, MemberVariable v) {
4848
/**
4949
* Get the size in bytes of the buffer pointed to by an expression (if this can be determined).
5050
*/
51+
language[monotonicAggregates]
5152
int getBufferSize(Expr bufferExpr, Element why) {
5253
exists(Variable bufferVar | bufferVar = bufferExpr.(VariableAccess).getTarget() |
5354
(
@@ -82,16 +83,19 @@ int getBufferSize(Expr bufferExpr, Element why) {
8283
why = bufferExpr
8384
) or (
8485
// dataflow (all sources must be the same size)
85-
forex(Expr def |
86+
result = min(Expr def |
8687
DataFlow::localFlowStep(DataFlow::exprNode(def), DataFlow::exprNode(bufferExpr)) |
87-
result = getBufferSize(def, _)
88+
getBufferSize(def, _)
89+
) and result = max(Expr def |
90+
DataFlow::localFlowStep(DataFlow::exprNode(def), DataFlow::exprNode(bufferExpr)) |
91+
getBufferSize(def, _)
8892
) and
8993

9094
// find reason
9195
exists(Expr def |
9296
DataFlow::localFlowStep(DataFlow::exprNode(def), DataFlow::exprNode(bufferExpr)) |
9397
why = def or
94-
result = getBufferSize(def, why)
98+
exists(getBufferSize(def, why))
9599
)
96100
) or exists(Type bufferType |
97101
// buffer is the address of a variable

0 commit comments

Comments
 (0)