Skip to content

Commit f1b5564

Browse files
authored
Merge pull request #20073 from d10c/d10c/diff-informed-phase-3-cpp
C++: Diff-informed queries: phase 3 (non-trivial locations)
2 parents 4199859 + 8978820 commit f1b5564

31 files changed

+397
-0
lines changed

cpp/ql/src/Critical/OverflowDestination.ql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ module OverflowDestinationConfig implements DataFlow::ConfigSig {
8282
nodeIsBarrierEqualityCandidate(node, access, checkedVar)
8383
)
8484
}
85+
86+
predicate observeDiffInformedIncrementalMode() { any() }
87+
88+
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
89+
90+
Location getASelectedSinkLocation(DataFlow::Node sink) {
91+
exists(FunctionCall fc | result = fc.getLocation() |
92+
sourceSized(fc, sink.asIndirectConvertedExpr())
93+
)
94+
}
8595
}
8696

8797
module OverflowDestination = TaintTracking::Global<OverflowDestinationConfig>;

cpp/ql/src/Likely Bugs/Format/NonConstantFormat.ql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ module NonConstFlowConfig implements DataFlow::ConfigSig {
168168
cannotContainString(t)
169169
)
170170
}
171+
172+
predicate observeDiffInformedIncrementalMode() { any() }
173+
174+
Location getASelectedSourceLocation(DataFlow::Node source) { none() }
175+
176+
Location getASelectedSinkLocation(DataFlow::Node sink) {
177+
result = sink.getLocation()
178+
or
179+
exists(FormattingFunctionCall call, Expr formatString | result = call.getLocation() |
180+
isSinkImpl(sink, formatString) and
181+
call.getArgument(call.getFormatParameterIndex()) = formatString
182+
)
183+
}
171184
}
172185

173186
module NonConstFlow = TaintTracking::Global<NonConstFlowConfig>;

cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ private module LeapYearCheckConfig implements DataFlow::ConfigSig {
215215
predicate isSink(DataFlow::Node sink) {
216216
exists(ChecksForLeapYearFunctionCall fc | sink.asExpr() = fc.getAnArgument())
217217
}
218+
219+
predicate observeDiffInformedIncrementalMode() {
220+
none() // only used negatively in UncheckedLeapYearAfterYearModification.ql
221+
}
218222
}
219223

220224
module LeapYearCheckFlow = DataFlow::Global<LeapYearCheckConfig>;
@@ -285,6 +289,14 @@ private module PossibleYearArithmeticOperationCheckConfig implements DataFlow::C
285289
aexpr.getLValue() = fa
286290
)
287291
}
292+
293+
predicate observeDiffInformedIncrementalMode() { any() }
294+
295+
Location getASelectedSourceLocation(DataFlow::Node source) {
296+
result = source.asExpr().getLocation()
297+
}
298+
299+
Location getASelectedSinkLocation(DataFlow::Node sink) { result = sink.asExpr().getLocation() }
288300
}
289301

290302
module PossibleYearArithmeticOperationCheckFlow =

cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ module TaintedPathConfig implements DataFlow::ConfigSig {
9393
// make sinks barriers so that we only report the closest instance
9494
isSink(node)
9595
}
96+
97+
predicate observeDiffInformedIncrementalMode() { any() }
98+
99+
Location getASelectedSinkLocation(DataFlow::Node sink) {
100+
result = sink.asIndirectArgument().getLocation()
101+
}
96102
}
97103

98104
module TaintedPath = TaintTracking::Global<TaintedPathConfig>;

cpp/ql/src/Security/CWE/CWE-078/ExecTainted.ql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ module ExecTaintConfig implements DataFlow::StateConfigSig {
150150
predicate isBarrierOut(DataFlow::Node node) {
151151
isSink(node, _) // Prevent duplicates along a call chain, since `shellCommand` will include wrappers
152152
}
153+
154+
predicate observeDiffInformedIncrementalMode() { any() }
155+
156+
Location getASelectedSinkLocation(DataFlow::Node sink) {
157+
exists(DataFlow::Node concatResult, Expr command, ExecState state |
158+
result = [concatResult.getLocation(), command.getLocation()] and
159+
isSink(sink, state) and
160+
isSinkImpl(sink, command, _) and
161+
concatResult = state.getOutgoingNode()
162+
)
163+
}
153164
}
154165

155166
module ExecTaint = TaintTracking::GlobalWithState<ExecTaintConfig>;

cpp/ql/src/Security/CWE/CWE-079/CgiXss.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ module Config implements DataFlow::ConfigSig {
3939
or
4040
node.asCertainDefinition().getUnspecifiedType() instanceof ArithmeticType
4141
}
42+
43+
predicate observeDiffInformedIncrementalMode() { any() }
44+
45+
Location getASelectedSourceLocation(DataFlow::Node source) {
46+
exists(QueryString query | result = query.getLocation() | query = source.asIndirectExpr())
47+
}
4248
}
4349

4450
module Flow = TaintTracking::Global<Config>;

cpp/ql/src/Security/CWE/CWE-089/SqlTainted.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ module SqlTaintedConfig implements DataFlow::ConfigSig {
5454
sql.barrierSqlArgument(input, _)
5555
)
5656
}
57+
58+
predicate observeDiffInformedIncrementalMode() { any() }
59+
60+
Location getASelectedSinkLocation(DataFlow::Node sink) {
61+
exists(Expr taintedArg | result = taintedArg.getLocation() | taintedArg = asSinkExpr(sink))
62+
}
5763
}
5864

5965
module SqlTainted = TaintTracking::Global<SqlTaintedConfig>;

cpp/ql/src/Security/CWE/CWE-120/UnboundedWrite.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ module Config implements DataFlow::ConfigSig {
124124
// Block flow if the node is guarded by any <, <= or = operations.
125125
node = DataFlow::BarrierGuard<lessThanOrEqual/3>::getABarrierNode()
126126
}
127+
128+
predicate observeDiffInformedIncrementalMode() { any() }
129+
130+
Location getASelectedSinkLocation(DataFlow::Node sink) {
131+
exists(BufferWrite bw | result = bw.getLocation() | isSink(sink, bw, _))
132+
}
127133
}
128134

129135
module Flow = TaintTracking::Global<Config>;

cpp/ql/src/Security/CWE/CWE-170/ImproperNullTerminationTainted.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ private module Config implements DataFlow::ConfigSig {
4343
}
4444

4545
predicate isSink(DataFlow::Node sink) { isSink(sink, _) }
46+
47+
predicate observeDiffInformedIncrementalMode() { any() }
48+
49+
Location getASelectedSinkLocation(DataFlow::Node sink) {
50+
exists(VariableAccess va | result = va.getLocation() | isSink(sink, va))
51+
}
4652
}
4753

4854
module Flow = TaintTracking::Global<Config>;

cpp/ql/src/Security/CWE/CWE-190/ArithmeticTainted.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ module Config implements DataFlow::ConfigSig {
106106
not iTo instanceof PointerArithmeticInstruction
107107
)
108108
}
109+
110+
predicate observeDiffInformedIncrementalMode() { any() }
111+
112+
Location getASelectedSinkLocation(DataFlow::Node sink) {
113+
exists(Expr e | result = e.getLocation() | isSink(sink, _, e))
114+
}
109115
}
110116

111117
module Flow = TaintTracking::Global<Config>;

0 commit comments

Comments
 (0)