Skip to content

Commit 0d3e47b

Browse files
committed
C++: Pick the offset expression as the sink in 'cpp/unclear-array-index-validation' (and not the array expression).
1 parent 693eca2 commit 0d3e47b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

cpp/ql/src/Security/CWE/CWE-129/ImproperArrayIndexValidation.ql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ predicate linearBoundControls(BasicBlock controlled, SsaDefinition def, StackVar
3535
)
3636
}
3737

38-
predicate isUnboundedArrayIndex(DataFlow::Node sink, VariableAccess offsetExpr) {
39-
offsetExpr = sink.asExpr().(ArrayExpr).getArrayOffset() and
40-
not hasUpperBound(offsetExpr)
41-
}
42-
4338
predicate readsVariable(LoadInstruction load, Variable var) {
4439
load.getSourceAddress().(VariableAddressInstruction).getASTVariable() = var
4540
}
@@ -79,16 +74,21 @@ class ImproperArrayIndexValidationConfig extends TaintTracking::Configuration {
7974
)
8075
}
8176

82-
override predicate isSink(DataFlow::Node sink) { isUnboundedArrayIndex(sink, _) }
77+
override predicate isSink(DataFlow::Node sink) {
78+
exists(ArrayExpr arrayExpr, VariableAccess offsetExpr |
79+
offsetExpr = arrayExpr.getArrayOffset() and
80+
sink.asExpr() = offsetExpr and
81+
not hasUpperBound(offsetExpr)
82+
)
83+
}
8384
}
8485

8586
from
86-
VariableAccess offsetExpr, ImproperArrayIndexValidationConfig conf, DataFlow::PathNode source,
87-
DataFlow::PathNode sink, string sourceType
87+
ImproperArrayIndexValidationConfig conf, DataFlow::PathNode source, DataFlow::PathNode sink,
88+
string sourceType
8889
where
8990
conf.hasFlowPath(source, sink) and
90-
isFlowSource(source.getNode(), sourceType) and
91-
isUnboundedArrayIndex(sink.getNode(), offsetExpr)
91+
isFlowSource(source.getNode(), sourceType)
9292
select sink.getNode(), source, sink,
9393
"$@ flows to here and is used in an array indexing expression, potentially causing an invalid access.",
9494
source.getNode(), sourceType

0 commit comments

Comments
 (0)