@@ -68,13 +68,19 @@ newtype TRegexParseMode =
68
68
MkUnicode ( ) // Unicode UAX 29 word boundary mode
69
69
70
70
class RegexParseMode extends TRegexParseMode {
71
- string toString ( ) {
72
- ( this = MkIgnoreCase ( ) and result = "IGNORECASE" ) or
73
- ( this = MkVerbose ( ) and result = "VERBOSE" ) or
74
- ( this = MkDotAll ( ) and result = "DOTALL" ) or
75
- ( this = MkMultiLine ( ) and result = "MULTILINE" ) or
76
- ( this = MkUnicode ( ) and result = "UNICODE" )
71
+ string getName ( ) {
72
+ this = MkIgnoreCase ( ) and result = "IGNORECASE"
73
+ or
74
+ this = MkVerbose ( ) and result = "VERBOSE"
75
+ or
76
+ this = MkDotAll ( ) and result = "DOTALL"
77
+ or
78
+ this = MkMultiLine ( ) and result = "MULTILINE"
79
+ or
80
+ this = MkUnicode ( ) and result = "UNICODE"
77
81
}
82
+
83
+ string toString ( ) { result = this .getName ( ) }
78
84
}
79
85
80
86
/**
@@ -91,7 +97,9 @@ class RegexAdditionalFlowStep extends Unit {
91
97
* Holds if the step from `node1` to `node2` either sets (`isSet` = true)
92
98
* or unsets (`isSet` = false) parse mode `mode` for the regular expression.
93
99
*/
94
- abstract predicate modifiesParseMode ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo , RegexParseMode mode , boolean isSet ) ;
100
+ abstract predicate modifiesParseMode (
101
+ DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo , RegexParseMode mode , boolean isSet
102
+ ) ;
95
103
}
96
104
97
105
/**
@@ -102,29 +110,27 @@ class StandardRegexAdditionalFlowStep extends RegexAdditionalFlowStep {
102
110
this .modifiesParseMode ( nodeFrom , nodeTo , _, _)
103
111
}
104
112
105
- override predicate modifiesParseMode ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo , RegexParseMode mode , boolean isSet )
106
- {
113
+ override predicate modifiesParseMode (
114
+ DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo , RegexParseMode mode , boolean isSet
115
+ ) {
107
116
exists ( CallExpr ce |
108
117
nodeFrom .asExpr ( ) = ce .getQualifier ( ) and
109
118
nodeTo .asExpr ( ) = ce and
110
119
// decode the parse mode being set
111
120
(
112
- (
113
- ce .getStaticTarget ( ) .( Method ) .hasQualifiedName ( "Regex" , "ignoresCase(_:)" ) and
114
- mode = MkIgnoreCase ( )
115
- ) or (
116
- ce .getStaticTarget ( ) .( Method ) .hasQualifiedName ( "Regex" , "dotMatchesNewlines(_:)" ) and
117
- mode = MkDotAll ( )
118
- ) or (
119
- ce .getStaticTarget ( ) .( Method ) .hasQualifiedName ( "Regex" , "anchorsMatchLineEndings(_:)" ) and
120
- mode = MkMultiLine ( )
121
- )
121
+ ce .getStaticTarget ( ) .( Method ) .hasQualifiedName ( "Regex" , "ignoresCase(_:)" ) and
122
+ mode = MkIgnoreCase ( )
123
+ or
124
+ ce .getStaticTarget ( ) .( Method ) .hasQualifiedName ( "Regex" , "dotMatchesNewlines(_:)" ) and
125
+ mode = MkDotAll ( )
126
+ or
127
+ ce .getStaticTarget ( ) .( Method ) .hasQualifiedName ( "Regex" , "anchorsMatchLineEndings(_:)" ) and
128
+ mode = MkMultiLine ( )
122
129
) and
123
130
// decode the value being set
124
- if ce .getArgument ( 0 ) .getExpr ( ) .( BooleanLiteralExpr ) .getValue ( ) = false then
125
- isSet = false // mode is set to false
126
- else
127
- isSet = true // mode is set to true OR mode is set to default (=true) OR mode is set to an unknown value
131
+ if ce .getArgument ( 0 ) .getExpr ( ) .( BooleanLiteralExpr ) .getValue ( ) = false
132
+ then isSet = false // mode is set to false
133
+ else isSet = true // mode is set to true OR mode is set to default (=true) OR mode is set to an unknown value
128
134
)
129
135
}
130
136
}
@@ -168,9 +174,8 @@ abstract class RegexEval extends CallExpr {
168
174
RegexParseMode getAParseMode ( ) {
169
175
exists ( DataFlow:: Node setNode |
170
176
// parse mode flag is set
171
- any ( RegexAdditionalFlowStep s ) .modifiesParseMode ( _, setNode , result , true )
172
- and
173
- // reaches here
177
+ any ( RegexAdditionalFlowStep s ) .modifiesParseMode ( _, setNode , result , true ) and
178
+ // reaches this eval
174
179
RegexParseModeFlow:: flow ( setNode , DataFlow:: exprNode ( this .getRegexInput ( ) ) )
175
180
)
176
181
}
0 commit comments