Skip to content

Commit 28e03a8

Browse files
authored
Merge pull request github#7738 from hvitved/ruby/action-controller-perf
Ruby: Fix bad join in `ActionControllerHelperMethod`
2 parents 2c27a07 + 49488fa commit 28e03a8

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ class ActionControllerRedirectResponse extends HTTP::Server::HttpRedirectRespons
202202
}
203203
}
204204

205+
pragma[nomagic]
206+
private predicate isActionControllerMethod(Method m, string name, ActionControllerControllerClass c) {
207+
m.getName() = name and
208+
m.getEnclosingModule() = c
209+
}
210+
211+
pragma[nomagic]
212+
private predicate actionControllerHasHelperMethodCall(ActionControllerControllerClass c, string name) {
213+
exists(MethodCall mc |
214+
mc.getMethodName() = "helper_method" and
215+
mc.getAnArgument().getConstantValue().isStringOrSymbol(name) and
216+
mc.getEnclosingModule() = c
217+
)
218+
}
219+
205220
/**
206221
* A method in an `ActionController` class that is accessible from within a
207222
* Rails view as a helper method. For instance, in:
@@ -222,11 +237,9 @@ class ActionControllerHelperMethod extends Method {
222237
private ActionControllerControllerClass controllerClass;
223238

224239
ActionControllerHelperMethod() {
225-
this.getEnclosingModule() = controllerClass and
226-
exists(MethodCall helperMethodMarker |
227-
helperMethodMarker.getMethodName() = "helper_method" and
228-
helperMethodMarker.getAnArgument().getConstantValue().isStringOrSymbol(this.getName()) and
229-
helperMethodMarker.getEnclosingModule() = controllerClass
240+
exists(string name |
241+
isActionControllerMethod(this, name, controllerClass) and
242+
actionControllerHasHelperMethodCall(controllerClass, name)
230243
)
231244
}
232245

0 commit comments

Comments
 (0)