Skip to content

Commit eff7cf6

Browse files
authored
Merge pull request #8538 from hvitved/ruby/regexpterm-location-perf
Ruby: Fix bad join-order in `RegExpTerm::hasLocationInfo`
2 parents 2699412 + 13be991 commit eff7cf6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,21 @@ class RegExpTerm extends RegExpParent {
190190

191191
Location getLocation() { result = re.getLocation() }
192192

193+
pragma[noinline]
194+
private predicate componentHasLocationInfo(
195+
int i, string filepath, int startline, int startcolumn, int endline, int endcolumn
196+
) {
197+
re.getComponent(i)
198+
.getLocation()
199+
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
200+
}
201+
193202
predicate hasLocationInfo(
194203
string filepath, int startline, int startcolumn, int endline, int endcolumn
195204
) {
196205
exists(int re_start, int re_end |
197-
re.getComponent(0).getLocation().hasLocationInfo(filepath, startline, re_start, _, _) and
198-
re.getComponent(re.getNumberOfComponents() - 1)
199-
.getLocation()
200-
.hasLocationInfo(filepath, _, _, endline, re_end)
201-
|
206+
this.componentHasLocationInfo(0, filepath, startline, re_start, _, _) and
207+
this.componentHasLocationInfo(re.getNumberOfComponents() - 1, filepath, _, _, endline, re_end) and
202208
startcolumn = re_start + start and
203209
endcolumn = re_start + end - 1
204210
)

0 commit comments

Comments
 (0)