File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -610,15 +610,22 @@ private module Impl implements RegexTreeViewSig {
610
610
/**
611
611
* Holds if this is a unicode escape.
612
612
*/
613
- private predicate isUnicode ( ) { this .getText ( ) .prefix ( 2 ) = [ "\\u" , "\\U" ] }
613
+ private predicate isUnicode ( ) { this .getText ( ) .prefix ( 2 ) = [ "\\u" , "\\U" , "\\x" ] }
614
614
615
615
/**
616
616
* Gets the unicode char for this escape.
617
617
* E.g. for `\u0061` this returns "a".
618
618
*/
619
- private string getUnicode ( ) {
619
+ private string getUnicode ( ) { result = parseHexInt ( this .getHexString ( ) ) .toUnicode ( ) }
620
+
621
+ /**
622
+ * Gets the part of this escape that is a hexidecimal string.
623
+ */
624
+ private string getHexString ( ) {
620
625
this .isUnicode ( ) and
621
- result = parseHexInt ( this .getText ( ) .suffix ( 2 ) ) .toUnicode ( )
626
+ if this .getText ( ) .matches ( [ "\\x{%" , "\\u{%" ] ) // \x{hh...} or \u{hh...}
627
+ then result = this .getText ( ) .substring ( 3 , this .getText ( ) .length ( ) - 1 )
628
+ else result = this .getText ( ) .suffix ( 2 ) // \xhh or \uhhhh or \Uhhhhhhhh
622
629
}
623
630
}
624
631
Original file line number Diff line number Diff line change @@ -507,16 +507,16 @@ func myRegexpVariantsTests(myUrl: URL) throws {
507
507
// GOOD
508
508
_ = try Regex ( #"X(\U00000061|b)+Y"# ) . firstMatch ( in: tainted)
509
509
510
- // BAD TODO: we should get this one
510
+ // BAD
511
511
// attack string: "X" + "a" x lots
512
- _ = try Regex ( #"X(\x61|a)*Y"# ) . firstMatch ( in: tainted) // $ MISSING: redos-vulnerable=
512
+ _ = try Regex ( #"X(\x61|a)*Y"# ) . firstMatch ( in: tainted) // $ redos-vulnerable=
513
513
514
514
// GOOD
515
515
_ = try Regex ( #"X(\x61|b)+Y"# ) . firstMatch ( in: tainted)
516
516
517
- // BAD TODO: we should get this one
517
+ // BAD
518
518
// attack string: "X" + "a" x lots
519
- _ = try Regex ( #"X(\x{061}|a)*Y"# ) . firstMatch ( in: tainted) // $ MISSING: redos-vulnerable=
519
+ _ = try Regex ( #"X(\x{061}|a)*Y"# ) . firstMatch ( in: tainted) // $ redos-vulnerable=
520
520
521
521
// GOOD
522
522
_ = try Regex ( #"X(\x{061}|b)+Y"# ) . firstMatch ( in: tainted)
You can’t perform that action at this time.
0 commit comments