Skip to content

Commit 8612116

Browse files
authored
Merge pull request #8364 from hvitved/ruby/fix-regex-parse
Ruby: Fix regex parsing of `/[|]/`
2 parents ec75bbc + 3bc8d08 commit 8612116

File tree

5 files changed

+129
-114
lines changed

5 files changed

+129
-114
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import codeql.ruby.security.performance.RegExpTreeView
2+
3+
query predicate nonUniqueChild(RegExpParent parent, int i, RegExpTerm child) {
4+
child = parent.getChild(i) and
5+
strictcount(parent.getChild(i)) > 1
6+
}
7+
8+
query predicate cyclic(RegExpParent parent) { parent = parent.getAChild+() }

ruby/ql/lib/codeql/ruby/security/performance/ParseRegExp.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ abstract class RegExp extends AST::StringlikeLiteral {
861861
* Whether the text in the range start,end is an alternation
862862
*/
863863
predicate alternation(int start, int end) {
864+
not this.inCharSet(start) and
864865
this.topLevel(start, end) and
865866
exists(int less | this.subalternation(start, less, _) and less < end)
866867
}

ruby/ql/lib/codeql/ruby/security/performance/RegExpTreeView.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class RegExpParent extends TRegExpParent {
6969

7070
RegExpTerm getChild(int i) { none() }
7171

72-
RegExpTerm getAChild() { result = this.getChild(_) }
72+
final RegExpTerm getAChild() { result = this.getChild(_) }
7373

7474
int getNumChild() { result = count(this.getAChild()) }
7575

0 commit comments

Comments
 (0)