@@ -8,38 +8,32 @@ import semmle.code.cpp.valuenumbering.GlobalValueNumbering
8
8
import semmle.code.cpp.ir.IR
9
9
10
10
/**
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.
16
13
*/
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" }
35
27
}
36
28
37
29
/**
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.
40
31
*/
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
43
37
}
44
38
45
39
/**
@@ -62,7 +56,7 @@ class XercesDomParserClass extends Class {
62
56
class XercesDomParserLibrary extends XmlLibrary {
63
57
XercesDomParserLibrary ( ) { this = "XercesDomParserLibrary" }
64
58
65
- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
59
+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
66
60
// source is the write on `this` of a call to the `XercesDOMParser`
67
61
// constructor.
68
62
exists ( Call call |
@@ -72,7 +66,7 @@ class XercesDomParserLibrary extends XmlLibrary {
72
66
)
73
67
}
74
68
75
- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
69
+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
76
70
// sink is the read of the qualifier of a call to `AbstractDOMParser.parse`.
77
71
exists ( Call call |
78
72
call .getTarget ( ) .getClassAndName ( "parse" ) instanceof AbstractDomParserClass and
@@ -107,7 +101,7 @@ class CreateLSParser extends Function {
107
101
class CreateLSParserLibrary extends XmlLibrary {
108
102
CreateLSParserLibrary ( ) { this = "CreateLSParserLibrary" }
109
103
110
- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
104
+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
111
105
// source is the result of a call to `createLSParser`.
112
106
exists ( Call call |
113
107
call .getTarget ( ) instanceof CreateLSParser and
@@ -116,7 +110,7 @@ class CreateLSParserLibrary extends XmlLibrary {
116
110
)
117
111
}
118
112
119
- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
113
+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
120
114
// sink is the read of the qualifier of a call to `DOMLSParserClass.parse`.
121
115
exists ( Call call |
122
116
call .getTarget ( ) .getClassAndName ( "parse" ) instanceof DomLSParserClass and
@@ -147,7 +141,7 @@ class Sax2XmlReader extends Class {
147
141
class SaxParserLibrary extends XmlLibrary {
148
142
SaxParserLibrary ( ) { this = "SaxParserLibrary" }
149
143
150
- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
144
+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
151
145
// source is the write on `this` of a call to the `SAXParser`
152
146
// constructor.
153
147
exists ( Call call |
@@ -157,7 +151,7 @@ class SaxParserLibrary extends XmlLibrary {
157
151
)
158
152
}
159
153
160
- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
154
+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
161
155
// sink is the read of the qualifier of a call to `SAXParser.parse`.
162
156
exists ( Call call |
163
157
call .getTarget ( ) .getClassAndName ( "parse" ) instanceof SaxParserClass and
@@ -185,7 +179,7 @@ class CreateXmlReader extends Function {
185
179
class Sax2XmlReaderLibrary extends XmlLibrary {
186
180
Sax2XmlReaderLibrary ( ) { this = "Sax2XmlReaderLibrary" }
187
181
188
- override predicate configurationSource ( DataFlow:: Node node , string flowstate ) {
182
+ override predicate configurationSource ( DataFlow:: Node node , TXxeFlowState flowstate ) {
189
183
// source is the result of a call to `createXMLReader`.
190
184
exists ( Call call |
191
185
call .getTarget ( ) instanceof CreateXmlReader and
@@ -194,7 +188,7 @@ class Sax2XmlReaderLibrary extends XmlLibrary {
194
188
)
195
189
}
196
190
197
- override predicate configurationSink ( DataFlow:: Node node , string flowstate ) {
191
+ override predicate configurationSink ( DataFlow:: Node node , TXxeFlowState flowstate ) {
198
192
// sink is the read of the qualifier of a call to `SAX2XMLReader.parse`.
199
193
exists ( Call call |
200
194
call .getTarget ( ) .getClassAndName ( "parse" ) instanceof Sax2XmlReader and
@@ -227,7 +221,7 @@ class DisableDefaultEntityResolutionTransformer extends XxeFlowStateTransformer
227
221
)
228
222
}
229
223
230
- final override XxeFlowState transform ( XxeFlowState flowstate ) {
224
+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
231
225
exists ( int createEntityReferenceNodes |
232
226
encodeXercesFlowState ( flowstate , _, createEntityReferenceNodes ) and
233
227
(
@@ -258,7 +252,7 @@ class CreateEntityReferenceNodesTransformer extends XxeFlowStateTransformer {
258
252
)
259
253
}
260
254
261
- final override XxeFlowState transform ( XxeFlowState flowstate ) {
255
+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
262
256
exists ( int disabledDefaultEntityResolution |
263
257
encodeXercesFlowState ( flowstate , disabledDefaultEntityResolution , _) and
264
258
(
@@ -301,7 +295,7 @@ class SetFeatureTransformer extends XxeFlowStateTransformer {
301
295
)
302
296
}
303
297
304
- final override XxeFlowState transform ( XxeFlowState flowstate ) {
298
+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
305
299
exists ( int createEntityReferenceNodes |
306
300
encodeXercesFlowState ( flowstate , _, createEntityReferenceNodes ) and
307
301
(
@@ -359,7 +353,7 @@ class DomConfigurationSetParameterTransformer extends XxeFlowStateTransformer {
359
353
)
360
354
}
361
355
362
- final override XxeFlowState transform ( XxeFlowState flowstate ) {
356
+ final override TXxeFlowState transform ( TXxeFlowState flowstate ) {
363
357
exists ( int createEntityReferenceNodes |
364
358
encodeXercesFlowState ( flowstate , _, createEntityReferenceNodes ) and
365
359
(
0 commit comments