@@ -8,38 +8,32 @@ import semmle.code.cpp.valuenumbering.GlobalValueNumbering
88import semmle.code.cpp.ir.IR
99
1010/**
11- * Gets a valid flow state for `AbstractDOMParser` or `SAXParser` flow.
12- *
13- * These flow states take the form `Xerces-A-B`, where:
14- * - A is 1 if `setDisableDefaultEntityResolution` is `true`, 0 otherwise.
15- * - B is 1 if `setCreateEntityReferenceNodes` is `true`, 0 otherwise.
11+ * A flow state representing the configuration of an `AbstractDOMParser` or
12+ * `SAXParser` object.
1613 */
17- predicate encodeXercesFlowState (
18- string flowstate , int disabledDefaultEntityResolution , int createEntityReferenceNodes
19- ) {
20- flowstate = "Xerces-0-0" and
21- disabledDefaultEntityResolution = 0 and
22- createEntityReferenceNodes = 0
23- or
24- flowstate = "Xerces-0-1" and
25- disabledDefaultEntityResolution = 0 and
26- createEntityReferenceNodes = 1
27- or
28- flowstate = "Xerces-1-0" and
29- disabledDefaultEntityResolution = 1 and
30- createEntityReferenceNodes = 0
31- or
32- flowstate = "Xerces-1-1" and
33- disabledDefaultEntityResolution = 1 and
34- createEntityReferenceNodes = 1
14+ class XercesFlowState extends TXxeFlowState {
15+ int disabledDefaultEntityResolution ;
16+ int createEntityReferenceNodes ;
17+
18+ XercesFlowState ( ) {
19+ this = TXercesFlowState ( disabledDefaultEntityResolution , createEntityReferenceNodes )
20+ }
21+
22+ int getDisabledDefaultEntityResolution ( ) { result = disabledDefaultEntityResolution }
23+
24+ int getCreateEntityReferenceNodes ( ) { result = createEntityReferenceNodes }
25+
26+ string toString ( ) { result = "XercesFlowState" }
3527}
3628
3729/**
38- * A flow state representing the configuration of an `AbstractDOMParser` or
39- * `SAXParser` object.
30+ * Gets a valid flow state for `AbstractDOMParser` or `SAXParser` flow.
4031 */
41- class XercesFlowState extends XxeFlowState {
42- XercesFlowState ( ) { encodeXercesFlowState ( this , _, _) }
32+ predicate encodeXercesFlowState (
33+ XercesFlowState flowstate , int disabledDefaultEntityResolution , int createEntityReferenceNodes
34+ ) {
35+ flowstate .getDisabledDefaultEntityResolution ( ) = disabledDefaultEntityResolution and
36+ flowstate .getCreateEntityReferenceNodes ( ) = createEntityReferenceNodes
4337}
4438
4539/**
@@ -62,7 +56,7 @@ class XercesDomParserClass extends Class {
6256class XercesDomParserLibrary extends XmlLibrary {
6357 XercesDomParserLibrary ( ) { this = "XercesDomParserLibrary" }
6458
65- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
59+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
6660 // source is the write on `this` of a call to the `XercesDOMParser`
6761 // constructor.
6862 exists ( Call call |
@@ -72,7 +66,7 @@ class XercesDomParserLibrary extends XmlLibrary {
7266 )
7367 }
7468
75- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
69+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
7670 // sink is the read of the qualifier of a call to `AbstractDOMParser.parse`.
7771 exists ( Call call |
7872 call .getTarget ( ) .getClassAndName ( "parse" ) instanceof AbstractDomParserClass and
@@ -107,7 +101,7 @@ class CreateLSParser extends Function {
107101class CreateLSParserLibrary extends XmlLibrary {
108102 CreateLSParserLibrary ( ) { this = "CreateLSParserLibrary" }
109103
110- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
104+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
111105 // source is the result of a call to `createLSParser`.
112106 exists ( Call call |
113107 call .getTarget ( ) instanceof CreateLSParser and
@@ -116,7 +110,7 @@ class CreateLSParserLibrary extends XmlLibrary {
116110 )
117111 }
118112
119- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
113+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
120114 // sink is the read of the qualifier of a call to `DOMLSParserClass.parse`.
121115 exists ( Call call |
122116 call .getTarget ( ) .getClassAndName ( "parse" ) instanceof DomLSParserClass and
@@ -147,7 +141,7 @@ class Sax2XmlReader extends Class {
147141class SaxParserLibrary extends XmlLibrary {
148142 SaxParserLibrary ( ) { this = "SaxParserLibrary" }
149143
150- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
144+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
151145 // source is the write on `this` of a call to the `SAXParser`
152146 // constructor.
153147 exists ( Call call |
@@ -157,7 +151,7 @@ class SaxParserLibrary extends XmlLibrary {
157151 )
158152 }
159153
160- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
154+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
161155 // sink is the read of the qualifier of a call to `SAXParser.parse`.
162156 exists ( Call call |
163157 call .getTarget ( ) .getClassAndName ( "parse" ) instanceof SaxParserClass and
@@ -185,7 +179,7 @@ class CreateXmlReader extends Function {
185179class Sax2XmlReaderLibrary extends XmlLibrary {
186180 Sax2XmlReaderLibrary ( ) { this = "Sax2XmlReaderLibrary" }
187181
188- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
182+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
189183 // source is the result of a call to `createXMLReader`.
190184 exists ( Call call |
191185 call .getTarget ( ) instanceof CreateXmlReader and
@@ -194,7 +188,7 @@ class Sax2XmlReaderLibrary extends XmlLibrary {
194188 )
195189 }
196190
197- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
191+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
198192 // sink is the read of the qualifier of a call to `SAX2XMLReader.parse`.
199193 exists ( Call call |
200194 call .getTarget ( ) .getClassAndName ( "parse" ) instanceof Sax2XmlReader and
@@ -227,7 +221,7 @@ class DisableDefaultEntityResolutionTransformer extends XxeFlowStateTransformer
227221 )
228222 }
229223
230- final override XxeFlowState transform ( XxeFlowState flowstate ) {
224+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
231225 exists ( int createEntityReferenceNodes |
232226 encodeXercesFlowState ( flowstate , _, createEntityReferenceNodes ) and
233227 (
@@ -258,7 +252,7 @@ class CreateEntityReferenceNodesTransformer extends XxeFlowStateTransformer {
258252 )
259253 }
260254
261- final override XxeFlowState transform ( XxeFlowState flowstate ) {
255+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
262256 exists ( int disabledDefaultEntityResolution |
263257 encodeXercesFlowState ( flowstate , disabledDefaultEntityResolution , _) and
264258 (
@@ -301,7 +295,7 @@ class SetFeatureTransformer extends XxeFlowStateTransformer {
301295 )
302296 }
303297
304- final override XxeFlowState transform ( XxeFlowState flowstate ) {
298+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
305299 exists ( int createEntityReferenceNodes |
306300 encodeXercesFlowState ( flowstate , _, createEntityReferenceNodes ) and
307301 (
@@ -359,7 +353,7 @@ class DomConfigurationSetParameterTransformer extends XxeFlowStateTransformer {
359353 )
360354 }
361355
362- final override XxeFlowState transform ( XxeFlowState flowstate ) {
356+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
363357 exists ( int createEntityReferenceNodes |
364358 encodeXercesFlowState ( flowstate , _, createEntityReferenceNodes ) and
365359 (
0 commit comments