Skip to content

Commit 4b1adc8

Browse files
committed
Constrain location overrides to actual sources/sinks
1 parent e344396 commit 4b1adc8

13 files changed

+45
-33
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ module UncontrolledArithConfig implements DataFlow::ConfigSig {
124124
predicate observeDiffInformedIncrementalMode() { any() }
125125

126126
Location getASelectedSourceLocation(DataFlow::Node source) {
127+
isSource(source) and
127128
result = [getExpr(source).getLocation(), source.getLocation()]
128129
}
129130
}

cpp/ql/src/Security/CWE/CWE-319/UseOfHttp.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ module HttpStringToUrlOpenConfig implements DataFlow::ConfigSig {
9191
predicate observeDiffInformedIncrementalMode() { any() }
9292

9393
Location getASelectedSourceLocation(DataFlow::Node source) {
94+
isSource(source) and
9495
result = [source.asIndirectExpr().getLocation(), source.getLocation()]
9596
}
9697
}

java/ql/lib/semmle/code/java/security/ArithmeticTaintedQuery.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ module ArithmeticOverflowConfig implements DataFlow::ConfigSig {
1919
}
2020

2121
Location getASelectedSinkLocation(DataFlow::Node sink) {
22-
result = sink.getLocation()
23-
or
24-
exists(ArithExpr exp | result = exp.getLocation() | overflowSink(exp, sink.asExpr()))
22+
exists(ArithExpr exp | result = [exp.getLocation(), sink.getLocation()] |
23+
overflowSink(exp, sink.asExpr())
24+
)
2525
}
2626
}
2727

@@ -45,9 +45,9 @@ module ArithmeticUnderflowConfig implements DataFlow::ConfigSig {
4545
}
4646

4747
Location getASelectedSinkLocation(DataFlow::Node sink) {
48-
result = sink.getLocation()
49-
or
50-
exists(ArithExpr exp | result = exp.getLocation() | underflowSink(exp, sink.asExpr()))
48+
exists(ArithExpr exp | result = [exp.getLocation(), sink.getLocation()] |
49+
underflowSink(exp, sink.asExpr())
50+
)
5151
}
5252
}
5353

java/ql/lib/semmle/code/java/security/ArithmeticUncontrolledQuery.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ module ArithmeticUncontrolledOverflowConfig implements DataFlow::ConfigSig {
2525
}
2626

2727
Location getASelectedSinkLocation(DataFlow::Node sink) {
28-
result = sink.getLocation()
29-
or
30-
exists(ArithExpr exp | result = exp.getLocation() | overflowSink(exp, sink.asExpr()))
28+
exists(ArithExpr exp | result = [exp.getLocation(), sink.getLocation()] |
29+
overflowSink(exp, sink.asExpr())
30+
)
3131
}
3232
}
3333

@@ -48,9 +48,9 @@ module ArithmeticUncontrolledUnderflowConfig implements DataFlow::ConfigSig {
4848
}
4949

5050
Location getASelectedSinkLocation(DataFlow::Node sink) {
51-
result = sink.getLocation()
52-
or
53-
exists(ArithExpr exp | result = exp.getLocation() | underflowSink(exp, sink.asExpr()))
51+
exists(ArithExpr exp | result = [exp.getLocation(), sink.getLocation()] |
52+
underflowSink(exp, sink.asExpr())
53+
)
5454
}
5555
}
5656

java/ql/lib/semmle/code/java/security/BrokenCryptoAlgorithmQuery.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ module InsecureCryptoConfig implements DataFlow::ConfigSig {
3535
predicate observeDiffInformedIncrementalMode() { any() }
3636

3737
Location getASelectedSinkLocation(DataFlow::Node sink) {
38-
result = sink.getLocation()
39-
or
40-
exists(CryptoAlgoSpec c | sink.asExpr() = c.getAlgoSpec() | result = c.getLocation())
38+
exists(CryptoAlgoSpec c | sink.asExpr() = c.getAlgoSpec() |
39+
result = c.getLocation()
40+
or
41+
result = sink.getLocation()
42+
)
4143
}
4244
}
4345

java/ql/lib/semmle/code/java/security/CommandLineQuery.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ module InputToArgumentToExecFlowConfig implements DataFlow::ConfigSig {
6666
// ExecTainted.ql queries use the argument as the primary location;
6767
// ExecUnescaped.ql does not (used to prevent overlapping results).
6868
Location getASelectedSinkLocation(DataFlow::Node sink) {
69-
result = sink.getLocation()
70-
or
71-
exists(Expr argument | argumentToExec(argument, sink) | result = argument.getLocation())
69+
exists(Expr argument | argumentToExec(argument, sink) |
70+
result = argument.getLocation()
71+
or
72+
result = sink.getLocation()
73+
)
7274
}
7375
}
7476

java/ql/lib/semmle/code/java/security/ConditionalBypassQuery.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ module ConditionalBypassFlowConfig implements DataFlow::ConfigSig {
5151
predicate observeDiffInformedIncrementalMode() { any() }
5252

5353
Location getASelectedSinkLocation(DataFlow::Node sink) {
54-
result = sink.getLocation()
55-
or
56-
exists(MethodCall m, Expr e | result = [m, e].getLocation() |
54+
exists(MethodCall m, Expr e | result = [[m, e].getLocation(), sink.getLocation()] |
5755
conditionControlsMethod(m, e) and
5856
sink.asExpr() = e
5957
)

java/ql/lib/semmle/code/java/security/ImproperValidationOfArrayConstructionCodeSpecifiedQuery.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ module BoundedFlowSourceConfig implements DataFlow::ConfigSig {
2121
predicate observeDiffInformedIncrementalMode() { any() }
2222

2323
Location getASelectedSinkLocation(DataFlow::Node sink) {
24-
result = sink.getLocation()
25-
or
2624
exists(ArrayCreationExpr arrayCreation, CheckableArrayAccess arrayAccess |
27-
result = [arrayCreation, arrayAccess.getIndexExpr()].getLocation() and
25+
result = [arrayCreation, arrayAccess.getIndexExpr()].getLocation()
26+
or
27+
result = sink.getLocation()
28+
|
2829
arrayAccess.canThrowOutOfBoundsDueToEmptyArray(sink.asExpr(), arrayCreation)
2930
)
3031
}

java/ql/lib/semmle/code/java/security/ImproperValidationOfArrayConstructionQuery.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ module ImproperValidationOfArrayConstructionConfig implements DataFlow::ConfigSi
1818
predicate observeDiffInformedIncrementalMode() { any() }
1919

2020
Location getASelectedSinkLocation(DataFlow::Node sink) {
21-
result = sink.getLocation()
22-
or
2321
exists(ArrayCreationExpr arrayCreation, CheckableArrayAccess arrayAccess |
24-
result = [arrayCreation, arrayAccess.getIndexExpr()].getLocation() and
22+
result = [arrayCreation, arrayAccess.getIndexExpr()].getLocation()
23+
or
24+
result = sink.getLocation()
25+
|
2526
arrayAccess.canThrowOutOfBoundsDueToEmptyArray(sink.asExpr(), arrayCreation)
2627
)
2728
}

java/ql/lib/semmle/code/java/security/UnsafeDeserializationQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private module UnsafeDeserializationConfig implements DataFlow::ConfigSig {
313313
predicate observeDiffInformedIncrementalMode() { any() }
314314

315315
Location getASelectedSinkLocation(DataFlow::Node sink) {
316-
result = sink.getLocation()
316+
result = sink.(UnsafeDeserializationSink).getLocation()
317317
or
318318
result = sink.(UnsafeDeserializationSink).getMethodCall().getLocation()
319319
}

0 commit comments

Comments
 (0)