@@ -68,13 +68,19 @@ newtype TRegexParseMode =
6868 MkUnicode ( ) // Unicode UAX 29 word boundary mode
6969
7070class 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"
7781 }
82+
83+ string toString ( ) { result = this .getName ( ) }
7884}
7985
8086/**
@@ -91,7 +97,9 @@ class RegexAdditionalFlowStep extends Unit {
9197 * Holds if the step from `node1` to `node2` either sets (`isSet` = true)
9298 * or unsets (`isSet` = false) parse mode `mode` for the regular expression.
9399 */
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+ ) ;
95103}
96104
97105/**
@@ -102,29 +110,27 @@ class StandardRegexAdditionalFlowStep extends RegexAdditionalFlowStep {
102110 this .modifiesParseMode ( nodeFrom , nodeTo , _, _)
103111 }
104112
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+ ) {
107116 exists ( CallExpr ce |
108117 nodeFrom .asExpr ( ) = ce .getQualifier ( ) and
109118 nodeTo .asExpr ( ) = ce and
110119 // decode the parse mode being set
111120 (
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 ( )
122129 ) and
123130 // 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
128134 )
129135 }
130136}
@@ -168,9 +174,8 @@ abstract class RegexEval extends CallExpr {
168174 RegexParseMode getAParseMode ( ) {
169175 exists ( DataFlow:: Node setNode |
170176 // 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
174179 RegexParseModeFlow:: flow ( setNode , DataFlow:: exprNode ( this .getRegexInput ( ) ) )
175180 )
176181 }
0 commit comments