Skip to content

Commit 48455ec

Browse files
committed
C#: Improve performance of MissingXMLValidation query
1 parent e6dc36b commit 48455ec

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

csharp/ql/lib/semmle/code/csharp/frameworks/system/Xml.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ private Expr getBitwiseOrOperand(Expr e) { result = e.(BitwiseOrExpr).getAnOpera
136136

137137
/** A creation of an instance of `System.Xml.XmlReaderSettings`. */
138138
class XmlReaderSettingsCreation extends ObjectCreation {
139-
XmlReaderSettingsCreation() { this.getType() instanceof SystemXmlXmlReaderSettingsClass }
139+
private SystemXmlXmlReaderSettingsClass settings;
140+
141+
XmlReaderSettingsCreation() { settings = this.getType() }
140142

141143
/** Gets a value set on the `ValidationType` property, if any. */
142144
SystemXmlValidationType getValidationType() {
@@ -152,7 +154,7 @@ class XmlReaderSettingsCreation extends ObjectCreation {
152154

153155
/** Gets a value set for the given property in this local context. */
154156
private Expr getPropertyValue(Property p) {
155-
p = this.getType().(RefType).getAProperty() and
157+
p = settings.getAProperty() and
156158
exists(PropertyCall set, Expr arg |
157159
set.getTarget() = p.getSetter() and
158160
DataFlow::localExprFlow(this, set.getQualifier()) and

csharp/ql/lib/semmle/code/csharp/security/dataflow/MissingXMLValidationQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ deprecated class TaintTrackingConfiguration extends TaintTracking::Configuration
5252
private module MissingXmlValidationConfig implements DataFlow::ConfigSig {
5353
predicate isSource(DataFlow::Node source) { source instanceof Source }
5454

55-
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
55+
predicate isSink(DataFlow::Node sink) { exists(sink.(Sink).getReason()) }
5656

5757
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
5858
}

csharp/ql/test/query-tests/Security Features/CWE-112/MissingXMLValidation.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ edges
22
| MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:16:43:16:57 | access to local variable userProvidedXml : String | provenance | |
33
| MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:21:43:21:57 | access to local variable userProvidedXml : String | provenance | |
44
| MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:27:43:27:57 | access to local variable userProvidedXml : String | provenance | |
5-
| MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:35:43:35:57 | access to local variable userProvidedXml : String | provenance | |
65
| MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:45:43:45:57 | access to local variable userProvidedXml : String | provenance | |
76
| MissingXMLValidation.cs:12:34:12:56 | access to property QueryString : NameValueCollection | MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | provenance | |
87
| MissingXMLValidation.cs:12:34:12:56 | access to property QueryString : NameValueCollection | MissingXMLValidation.cs:12:34:12:75 | access to indexer : String | provenance | MaD:11390 |
98
| MissingXMLValidation.cs:12:34:12:75 | access to indexer : String | MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | provenance | |
109
| MissingXMLValidation.cs:16:43:16:57 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:16:26:16:58 | object creation of type StringReader | provenance | MaD:1162 |
1110
| MissingXMLValidation.cs:21:43:21:57 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:21:26:21:58 | object creation of type StringReader | provenance | MaD:1162 |
1211
| MissingXMLValidation.cs:27:43:27:57 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:27:26:27:58 | object creation of type StringReader | provenance | MaD:1162 |
13-
| MissingXMLValidation.cs:35:43:35:57 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:35:26:35:58 | object creation of type StringReader | provenance | MaD:1162 |
1412
| MissingXMLValidation.cs:45:43:45:57 | access to local variable userProvidedXml : String | MissingXMLValidation.cs:45:26:45:58 | object creation of type StringReader | provenance | MaD:1162 |
1513
nodes
1614
| MissingXMLValidation.cs:12:16:12:30 | access to local variable userProvidedXml : String | semmle.label | access to local variable userProvidedXml : String |
@@ -22,8 +20,6 @@ nodes
2220
| MissingXMLValidation.cs:21:43:21:57 | access to local variable userProvidedXml : String | semmle.label | access to local variable userProvidedXml : String |
2321
| MissingXMLValidation.cs:27:26:27:58 | object creation of type StringReader | semmle.label | object creation of type StringReader |
2422
| MissingXMLValidation.cs:27:43:27:57 | access to local variable userProvidedXml : String | semmle.label | access to local variable userProvidedXml : String |
25-
| MissingXMLValidation.cs:35:26:35:58 | object creation of type StringReader | semmle.label | object creation of type StringReader |
26-
| MissingXMLValidation.cs:35:43:35:57 | access to local variable userProvidedXml : String | semmle.label | access to local variable userProvidedXml : String |
2723
| MissingXMLValidation.cs:45:26:45:58 | object creation of type StringReader | semmle.label | object creation of type StringReader |
2824
| MissingXMLValidation.cs:45:43:45:57 | access to local variable userProvidedXml : String | semmle.label | access to local variable userProvidedXml : String |
2925
subpaths

0 commit comments

Comments
 (0)