Skip to content

Commit d0b627b

Browse files
committed
move the implementation detail of how regular-expressions are tracked into RegExpConfiguration.qll"
1 parent f516ccb commit d0b627b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

ruby/ql/lib/codeql/ruby/Regexp.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import regexp.RegExpTreeView // re-export
99
private import regexp.internal.ParseRegExp
10-
private import regexp.internal.RegExpConfiguration
10+
private import regexp.internal.RegExpConfiguration as RegExpConfiguration // TODO: other name?
1111
private import codeql.ruby.AST as Ast
1212
private import codeql.ruby.CFG
1313
private import codeql.ruby.DataFlow
@@ -122,7 +122,7 @@ class StdLibRegExpInterpretation extends RegExpInterpretation::Range {
122122
mce.getMethodName() = ["match", "match?"] and
123123
this = mce.getArgument(0) and
124124
// exclude https://ruby-doc.org/core-2.4.0/Regexp.html#method-i-match
125-
not mce.getReceiver() = trackRegexpType()
125+
not mce.getReceiver() = RegExpConfiguration::trackRegexpType()
126126
)
127127
}
128128
}
@@ -132,9 +132,7 @@ class StdLibRegExpInterpretation extends RegExpInterpretation::Range {
132132
* as a part of a regular expression.
133133
*/
134134
cached
135-
DataFlow::Node regExpSource(DataFlow::Node re) {
136-
exists(RegExpConfiguration c | c.hasFlow(result, re))
137-
}
135+
DataFlow::Node regExpSource(DataFlow::Node re) { result = RegExpConfiguration::regExpSource(re) }
138136

139137
/**
140138
* Holds if `exec` is a node where `regexp` is interpreted as a regular expression and
@@ -173,7 +171,7 @@ private predicate regexExecution(
173171
// also see `StdLibRegExpInterpretation`
174172
not (
175173
call.getMethodName() = ["match", "match?"] and
176-
call.getReceiver() = trackRegexpType()
174+
call.getReceiver() = RegExpConfiguration::trackRegexpType()
177175
)
178176
)
179177
or

ruby/ql/lib/codeql/ruby/regexp/internal/RegExpConfiguration.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
private import codeql.ruby.Regexp
1+
private import codeql.ruby.Regexp as RE
22
private import codeql.ruby.AST as Ast
33
private import codeql.ruby.CFG
44
private import codeql.ruby.DataFlow
@@ -30,7 +30,7 @@ class RegExpConfiguration extends Configuration {
3030

3131
override predicate isSink(DataFlow::Node sink, DataFlow::FlowState state) {
3232
state = "string" and
33-
sink instanceof RegExpInterpretation::Range
33+
sink instanceof RE::RegExpInterpretation::Range
3434
or
3535
state = "reg" and
3636
sink = any(RegexExecution exec).getRegex()
@@ -96,3 +96,8 @@ private DataFlow::LocalSourceNode trackRegexpType(TypeTracker t) {
9696
}
9797

9898
DataFlow::Node trackRegexpType() { trackRegexpType(TypeTracker::end()).flowsTo(result) }
99+
100+
cached
101+
DataFlow::Node regExpSource(DataFlow::Node re) {
102+
exists(RegExpConfiguration c | c.hasFlow(result, re))
103+
}

0 commit comments

Comments
 (0)