Skip to content

Commit d6e143a

Browse files
authored
Merge pull request github#14151 from MathiasVP/deduplicate-dataflow-results-take-3
C++: Deduplicate dataflow query results
2 parents 49d5765 + d528c96 commit d6e143a

File tree

51 files changed

+332
-890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+332
-890
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 183 additions & 104 deletions
Large diffs are not rendered by default.

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,9 +1956,7 @@ class TranslatedNonConstantAllocationSize extends TranslatedAllocationSize {
19561956
result = this.getExtent().getResult()
19571957
}
19581958

1959-
private TranslatedExpr getExtent() {
1960-
result = getTranslatedExpr(expr.getExtent().getFullyConverted())
1961-
}
1959+
TranslatedExpr getExtent() { result = getTranslatedExpr(expr.getExtent().getFullyConverted()) }
19621960
}
19631961

19641962
/**

cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ predicate hasSize(HeuristicAllocationExpr alloc, DataFlow::Node n, int state) {
7272
// Compute `delta` as the constant difference between `x` and `x + 1`.
7373
bounded1(any(Instruction instr | instr.getUnconvertedResultExpression() = size),
7474
any(LoadInstruction load | load.getUnconvertedResultExpression() = va), delta) and
75-
n.asConvertedExpr() = va.getFullyConverted() and
75+
n.asExpr() = va and
7676
state = delta
7777
)
7878
}
@@ -210,7 +210,7 @@ private module InterestingPointerAddInstruction {
210210
predicate isSource(DataFlow::Node source) {
211211
// The sources is the same as in the sources for the second
212212
// projection in the `AllocToInvalidPointerConfig` module.
213-
hasSize(source.asConvertedExpr(), _, _)
213+
hasSize(source.asExpr(), _, _)
214214
}
215215

216216
int fieldFlowBranchLimit() { result = allocationToInvalidPointerFieldFlowBranchLimit() }
@@ -243,7 +243,7 @@ private module InterestingPointerAddInstruction {
243243
*/
244244
predicate isInterestingSize(DataFlow::Node n) {
245245
exists(DataFlow::Node alloc |
246-
hasSize(alloc.asConvertedExpr(), n, _) and
246+
hasSize(alloc.asExpr(), n, _) and
247247
flow(alloc, _)
248248
)
249249
}
@@ -268,7 +268,7 @@ private module Config implements ProductFlow::StateConfigSig {
268268
// we use `state2` to remember that there was an offset (in this case an offset of `1`) added
269269
// to the size of the allocation. This state is then checked in `isSinkPair`.
270270
exists(unit) and
271-
hasSize(allocSource.asConvertedExpr(), sizeSource, sizeAddend)
271+
hasSize(allocSource.asExpr(), sizeSource, sizeAddend)
272272
}
273273

274274
int fieldFlowBranchLimit1() { result = allocationToInvalidPointerFieldFlowBranchLimit() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Expr asSinkExpr(DataFlow::Node node) {
3030
result = node.asIndirectArgument()
3131
or
3232
// We want the conversion so we only get one node for the expression
33-
result = node.asConvertedExpr()
33+
result = node.asExpr()
3434
}
3535

3636
module SqlTaintedConfig implements DataFlow::ConfigSig {

cpp/ql/src/Security/CWE/CWE-119/OverrunWriteProductFlow.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ predicate hasSize(HeuristicAllocationExpr alloc, DataFlow::Node n, int state) {
3838
// Compute `delta` as the constant difference between `x` and `x + 1`.
3939
bounded(any(Instruction instr | instr.getUnconvertedResultExpression() = size),
4040
any(LoadInstruction load | load.getUnconvertedResultExpression() = va), delta) and
41-
n.asConvertedExpr() = va.getFullyConverted() and
41+
n.asExpr() = va and
4242
state = delta
4343
)
4444
}
@@ -213,7 +213,7 @@ module StringSizeConfig implements ProductFlow::StateConfigSig {
213213
// we use `state2` to remember that there was an offset (in this case an offset of `1`) added
214214
// to the size of the allocation. This state is then checked in `isSinkPair`.
215215
exists(state1) and
216-
hasSize(bufSource.asConvertedExpr(), sizeSource, state2) and
216+
hasSize(bufSource.asExpr(), sizeSource, state2) and
217217
validState(sizeSource, state2)
218218
}
219219

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import TaintedAllocationSize::PathGraph
2626
* taint sink.
2727
*/
2828
predicate allocSink(HeuristicAllocationExpr alloc, DataFlow::Node sink) {
29-
exists(Expr e | e = sink.asConvertedExpr() |
29+
exists(Expr e | e = sink.asExpr() |
3030
e = alloc.getAChild() and
3131
e.getUnspecifiedType() instanceof IntegralType
3232
)

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,22 @@ class Encrypted extends Expr {
206206
* operation `nsr`.
207207
*/
208208
predicate isSinkSendRecv(DataFlow::Node sink, NetworkSendRecv nsr) {
209-
[sink.asIndirectConvertedExpr(), sink.asConvertedExpr()] = nsr.getDataExpr().getFullyConverted()
209+
[sink.asIndirectExpr(), sink.asExpr()] = nsr.getDataExpr()
210210
}
211211

212212
/**
213213
* Holds if `sink` is a node that is encrypted by `enc`.
214214
*/
215-
predicate isSinkEncrypt(DataFlow::Node sink, Encrypted enc) {
216-
sink.asConvertedExpr() = enc.getFullyConverted()
217-
}
215+
predicate isSinkEncrypt(DataFlow::Node sink, Encrypted enc) { sink.asExpr() = enc }
218216

219217
/**
220218
* Holds if `source` represents a use of a sensitive variable, or data returned by a
221219
* function returning sensitive data.
222220
*/
223221
predicate isSourceImpl(DataFlow::Node source) {
224-
exists(Expr e |
225-
e = source.asConvertedExpr() and
226-
e.getUnconverted().(VariableAccess).getTarget() instanceof SourceVariable and
227-
not e.hasConversion()
222+
exists(VariableAccess e |
223+
e = source.asExpr() and
224+
e.getTarget() instanceof SourceVariable
228225
)
229226
or
230227
source.asExpr().(FunctionCall).getTarget() instanceof SourceFunction

cpp/ql/src/Security/CWE/CWE-497/ExposedSystemData.ql

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ module ExposedSystemDataConfig implements DataFlow::ConfigSig {
3333
module ExposedSystemData = TaintTracking::Global<ExposedSystemDataConfig>;
3434

3535
from ExposedSystemData::PathNode source, ExposedSystemData::PathNode sink
36-
where
37-
ExposedSystemData::flowPath(source, sink) and
38-
not exists(
39-
DataFlow::Node alt // remove duplicate results on conversions
40-
|
41-
ExposedSystemData::flow(source.getNode(), alt) and
42-
alt.asConvertedExpr() = sink.getNode().asIndirectExpr() and
43-
alt != sink.getNode()
44-
)
36+
where ExposedSystemData::flowPath(source, sink)
4537
select sink, source, sink, "This operation exposes system data from $@.", source,
4638
source.getNode().toString()

cpp/ql/src/Security/CWE/CWE-497/SystemData.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EnvData extends SystemData {
3434
.regexpMatch(".*(user|host|admin|root|home|path|http|ssl|snmp|sock|port|proxy|pass|token|crypt|key).*")
3535
}
3636

37-
override DataFlow::Node getAnExpr() { result.asIndirectConvertedExpr() = this }
37+
override DataFlow::Node getAnExpr() { result.asIndirectExpr() = this }
3838

3939
override predicate isSensitive() {
4040
this.(EnvironmentRead)
@@ -50,7 +50,7 @@ class EnvData extends SystemData {
5050
class SqlClientInfo extends SystemData {
5151
SqlClientInfo() { this.(FunctionCall).getTarget().hasName("mysql_get_client_info") }
5252

53-
override DataFlow::Node getAnExpr() { result.asIndirectConvertedExpr() = this }
53+
override DataFlow::Node getAnExpr() { result.asIndirectExpr() = this }
5454

5555
override predicate isSensitive() { any() }
5656
}

cpp/ql/src/Security/CWE/CWE-611/Xerces.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class XercesDomParserLibrary extends XmlLibrary {
7070
// sink is the read of the qualifier of a call to `AbstractDOMParser.parse`.
7171
exists(Call call |
7272
call.getTarget().getClassAndName("parse") instanceof AbstractDomParserClass and
73-
call.getQualifier() = node.asIndirectConvertedExpr()
73+
call.getQualifier() = node.asIndirectExpr()
7474
) and
7575
flowstate instanceof XercesFlowState and
7676
not encodeXercesFlowState(flowstate, 1, 1) // safe configuration
@@ -114,7 +114,7 @@ class CreateLSParserLibrary extends XmlLibrary {
114114
// sink is the read of the qualifier of a call to `DOMLSParserClass.parse`.
115115
exists(Call call |
116116
call.getTarget().getClassAndName("parse") instanceof DomLSParserClass and
117-
call.getQualifier() = node.asIndirectConvertedExpr()
117+
call.getQualifier() = node.asIndirectExpr()
118118
) and
119119
flowstate instanceof XercesFlowState and
120120
not encodeXercesFlowState(flowstate, 1, 1) // safe configuration
@@ -155,7 +155,7 @@ class SaxParserLibrary extends XmlLibrary {
155155
// sink is the read of the qualifier of a call to `SAXParser.parse`.
156156
exists(Call call |
157157
call.getTarget().getClassAndName("parse") instanceof SaxParserClass and
158-
call.getQualifier() = node.asIndirectConvertedExpr()
158+
call.getQualifier() = node.asIndirectExpr()
159159
) and
160160
flowstate instanceof XercesFlowState and
161161
not encodeXercesFlowState(flowstate, 1, 1) // safe configuration
@@ -192,7 +192,7 @@ class Sax2XmlReaderLibrary extends XmlLibrary {
192192
// sink is the read of the qualifier of a call to `SAX2XMLReader.parse`.
193193
exists(Call call |
194194
call.getTarget().getClassAndName("parse") instanceof Sax2XmlReader and
195-
call.getQualifier() = node.asIndirectConvertedExpr()
195+
call.getQualifier() = node.asIndirectExpr()
196196
) and
197197
flowstate instanceof XercesFlowState and
198198
not encodeXercesFlowState(flowstate, 1, 1) // safe configuration

0 commit comments

Comments
 (0)