Skip to content

Commit 20f501d

Browse files
committed
C++: Change queries to use 'asExpr' instead of 'asConvertedExpr'.
1 parent cca6052 commit 20f501d

File tree

14 files changed

+28
-62
lines changed

14 files changed

+28
-62
lines changed

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/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
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
WARNING: Module TaintedWithPath has been deprecated and may be removed in future (tainted.ql:9,8-47)
22
WARNING: Predicate tainted has been deprecated and may be removed in future (tainted.ql:20,49-74)
33
testFailures
4-
| test_diff.cpp:100:10:100:14 | * ... | Unexpected result: ir-sink=98:17 |
5-
| test_diff.cpp:102:26:102:30 | (const char *)... | Unexpected result: ir-path=98:17 |
64
failures

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/annotate_path_to_sink/test_diff.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ int main(int argc, char *argv[]) {
9797

9898
char*** p = &argv; // $ ast,ir-path
9999

100-
sink(*p[0]); // $ ast ir-sink=96:26 ir-sink=98:18
100+
sink(*p[0]); // $ ast ir-sink=96:26 ir-sink=98:18 ir-sink=98:17
101101

102-
calls_sink_with_argv(*p[i]); // $ ir-path=96:26 ir-path=98:18 MISSING:ast
102+
calls_sink_with_argv(*p[i]); // $ ir-path=96:26 ir-path=98:18 ir-path=98:17 MISSING:ast
103103

104104
sink(*(argv + 1)); // $ ast ir-path ir-sink
105105

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
testFailures
2-
| realistic.cpp:61:14:61:55 | bufferLen | Unexpected result: ir= |
3-
| realistic.cpp:61:59:61:84 | // $ ast ir=53:47 ir=53:55 | Missing result:ir=53:47 |
4-
| realistic.cpp:61:59:61:84 | // $ ast ir=53:47 ir=53:55 | Missing result:ir=53:55 |
52
failures

0 commit comments

Comments
 (0)