Skip to content

Commit 1929a95

Browse files
committed
format
1 parent 6065e29 commit 1929a95

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

ql/lib/codeql/ruby/Concepts.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,9 @@ module XmlParserCall {
548548
class OrmInstantiation extends DataFlow::Node instanceof OrmInstantiation::Range {
549549
/** Holds if a call to `methodName` on this instance may return a field of this ORM object. */
550550
bindingset[methodName]
551-
predicate methodCallMayAccessField(string methodName) { super.methodCallMayAccessField(methodName) }
551+
predicate methodCallMayAccessField(string methodName) {
552+
super.methodCallMayAccessField(methodName)
553+
}
552554
}
553555

554556
/** Provides a class for modeling new ORM object instantiation APIs. */

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,23 @@ class ActiveRecordModelClass extends ClassDeclaration {
6565

6666
/**
6767
* Gets methods defined in this class that may access a field from the database.
68-
*/
68+
*/
6969
Method methodMayAccessField() {
7070
result = this.getAMethod() and
7171
// There is a value that can be returned by this method which may include field data
7272
exists(DataFlow::Node returned, ActiveRecordInstanceMethodCall cNode, MethodCall c |
73-
exprNodeReturnedFrom(returned, result) and cNode.flowsTo(returned) and c = cNode.asExpr().getExpr() |
73+
exprNodeReturnedFrom(returned, result) and
74+
cNode.flowsTo(returned) and
75+
c = cNode.asExpr().getExpr()
76+
|
7477
// The referenced method is not built-in, and...
75-
not isBuiltInMethodForActiveRecordModelInstance(c.getMethodName()) and (
78+
not isBuiltInMethodForActiveRecordModelInstance(c.getMethodName()) and
79+
(
7680
// TODO: this would be more accurate if we also checked methods defined in
7781
// super classes and mixins
78-
7982
// ...There is no matching method definition in the class, or...
80-
not exists(cNode.getInstance().getClass().getMethod(c.getMethodName())) or
83+
not exists(cNode.getInstance().getClass().getMethod(c.getMethodName()))
84+
or
8185
// ...the called method can access a field
8286
c.getATarget() = cNode.getInstance().getClass().methodMayAccessField()
8387
)
@@ -221,18 +225,20 @@ private string constantQualifiedName(ConstantWriteAccess w) {
221225
/**
222226
* A node that may evaluate to one or more `ActiveRecordModelClass` instances.
223227
*/
224-
abstract class ActiveRecordModelInstantiation extends OrmInstantiation::Range, DataFlow::LocalSourceNode {
228+
abstract class ActiveRecordModelInstantiation extends OrmInstantiation::Range,
229+
DataFlow::LocalSourceNode {
225230
abstract ActiveRecordModelClass getClass();
226231

227232
bindingset[methodName]
228233
override predicate methodCallMayAccessField(string methodName) {
229234
// The method is not a built-in, and...
230-
not isBuiltInMethodForActiveRecordModelInstance(methodName) and (
235+
not isBuiltInMethodForActiveRecordModelInstance(methodName) and
236+
(
231237
// ...There is no matching method definition in the class, or...
232-
not exists(this.getClass().getMethod(methodName)) or
238+
not exists(this.getClass().getMethod(methodName))
239+
or
233240
// ...the called method can access a field.
234-
exists(Method m |
235-
m = this.getClass().methodMayAccessField() |
241+
exists(Method m | m = this.getClass().methodMayAccessField() |
236242
// We rely on matching by name here as the call graph might not have
237243
m.getName() = methodName
238244
)
@@ -317,6 +323,8 @@ private class ActiveRecordInstance extends DataFlow::Node {
317323
// A call whose receiver may be an active record model object
318324
private class ActiveRecordInstanceMethodCall extends DataFlow::CallNode {
319325
private ActiveRecordInstance instance;
326+
320327
ActiveRecordInstanceMethodCall() { this.getReceiver() = instance }
328+
321329
ActiveRecordInstance getInstance() { result = instance }
322-
}
330+
}

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,37 @@ private predicate isPrivateKernelMethod(string method) {
6767

6868
string basicObjectInstanceMethodName() {
6969
result in [
70-
"equal?", "instance_eval", "instance_exec", "method_missing", "singleton_method_added",
71-
"singleton_method_removed", "singleton_method_undefined"
72-
]
70+
"equal?", "instance_eval", "instance_exec", "method_missing", "singleton_method_added",
71+
"singleton_method_removed", "singleton_method_undefined"
72+
]
7373
}
7474

7575
/**
7676
* Instance methods on `BasicObject`, which are available to all classes.
7777
*/
7878
class BasicObjectInstanceMethodCall extends UnknownMethodCall {
79-
BasicObjectInstanceMethodCall() {
80-
this.getMethodName() = basicObjectInstanceMethodName()
81-
}
79+
BasicObjectInstanceMethodCall() { this.getMethodName() = basicObjectInstanceMethodName() }
8280
}
8381

8482
string objectInstanceMethodName() {
8583
result in [
86-
"!~", "<=>", "===", "=~", "callable_methods", "define_singleton_method", "display",
87-
"do_until", "do_while", "dup", "enum_for", "eql?", "extend", "f", "freeze", "h", "hash",
88-
"inspect", "instance_of?", "instance_variable_defined?", "instance_variable_get",
89-
"instance_variable_set", "instance_variables", "is_a?", "itself", "kind_of?",
90-
"matching_methods", "method", "method_missing", "methods", "nil?", "object_id",
91-
"private_methods", "protected_methods", "public_method", "public_methods", "public_send",
92-
"remove_instance_variable", "respond_to?", "respond_to_missing?", "send",
93-
"shortest_abbreviation", "singleton_class", "singleton_method", "singleton_methods",
94-
"taint", "tainted?", "to_enum", "to_s", "trust", "untaint", "untrust", "untrusted?"
95-
]
84+
"!~", "<=>", "===", "=~", "callable_methods", "define_singleton_method", "display",
85+
"do_until", "do_while", "dup", "enum_for", "eql?", "extend", "f", "freeze", "h", "hash",
86+
"inspect", "instance_of?", "instance_variable_defined?", "instance_variable_get",
87+
"instance_variable_set", "instance_variables", "is_a?", "itself", "kind_of?",
88+
"matching_methods", "method", "method_missing", "methods", "nil?", "object_id",
89+
"private_methods", "protected_methods", "public_method", "public_methods", "public_send",
90+
"remove_instance_variable", "respond_to?", "respond_to_missing?", "send",
91+
"shortest_abbreviation", "singleton_class", "singleton_method", "singleton_methods", "taint",
92+
"tainted?", "to_enum", "to_s", "trust", "untaint", "untrust", "untrusted?"
93+
]
9694
}
9795

9896
/**
9997
* Instance methods on `Object`, which are available to all classes except `BasicObject`.
10098
*/
10199
class ObjectInstanceMethodCall extends UnknownMethodCall {
102-
ObjectInstanceMethodCall() {
103-
this.getMethodName() = objectInstanceMethodName()
104-
}
100+
ObjectInstanceMethodCall() { this.getMethodName() = objectInstanceMethodName() }
105101
}
106102

107103
/**

0 commit comments

Comments
 (0)