Skip to content

Commit 2f8086b

Browse files
committed
Ruby: Rename getAUse -> getAValueReachableFromSource
1 parent 573c5c5 commit 2f8086b

File tree

13 files changed

+59
-20
lines changed

13 files changed

+59
-20
lines changed

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module API {
9999
*
100100
* This includes indirect uses found via data flow.
101101
*/
102-
DataFlow::Node getAUse() {
102+
DataFlow::Node getAValueReachableFromSource() {
103103
exists(DataFlow::LocalSourceNode src | Impl::use(this, src) |
104104
Impl::trackUseNode(src).flowsTo(result)
105105
)
@@ -108,7 +108,7 @@ module API {
108108
/**
109109
* Gets an immediate use of the API component represented by this node.
110110
*
111-
* Unlike `getAUse()`, this predicate only gets the immediate references, not the indirect uses
111+
* Unlike `getAValueReachableFromSource()`, this predicate only gets the immediate references, not the indirect uses
112112
* found via data flow.
113113
*/
114114
DataFlow::LocalSourceNode asSource() { Impl::use(this, result) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ActionControllerControllerClass extends ClassDeclaration {
3333
// In Rails applications `ApplicationController` typically extends `ActionController::Base`, but we
3434
// treat it separately in case the `ApplicationController` definition is not in the database.
3535
API::getTopLevelMember("ApplicationController")
36-
].getASubclass().getAUse().asExpr().getExpr()
36+
].getASubclass().getAValueReachableFromSource().asExpr().getExpr()
3737
}
3838

3939
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ActiveRecordModelClass extends ClassDeclaration {
5454
// In Rails applications `ApplicationRecord` typically extends `ActiveRecord::Base`, but we
5555
// treat it separately in case the `ApplicationRecord` definition is not in the database.
5656
API::getTopLevelMember("ApplicationRecord")
57-
].getASubclass().getAUse().asExpr().getExpr()
57+
].getASubclass().getAValueReachableFromSource().asExpr().getExpr()
5858
}
5959

6060
// Gets the class declaration for this class and all of its super classes

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ private API::Node graphQlSchema() { result = API::getTopLevelMember("GraphQL").g
4141
private class GraphqlRelayClassicMutationClass extends ClassDeclaration {
4242
GraphqlRelayClassicMutationClass() {
4343
this.getSuperclassExpr() =
44-
graphQlSchema().getMember("RelayClassicMutation").getASubclass*().getAUse().asExpr().getExpr()
44+
graphQlSchema()
45+
.getMember("RelayClassicMutation")
46+
.getASubclass*()
47+
.getAValueReachableFromSource()
48+
.asExpr()
49+
.getExpr()
4550
}
4651
}
4752

@@ -71,7 +76,12 @@ private class GraphqlRelayClassicMutationClass extends ClassDeclaration {
7176
private class GraphqlSchemaResolverClass extends ClassDeclaration {
7277
GraphqlSchemaResolverClass() {
7378
this.getSuperclassExpr() =
74-
graphQlSchema().getMember("Resolver").getASubclass().getAUse().asExpr().getExpr()
79+
graphQlSchema()
80+
.getMember("Resolver")
81+
.getASubclass()
82+
.getAValueReachableFromSource()
83+
.asExpr()
84+
.getExpr()
7585
}
7686
}
7787

@@ -92,7 +102,12 @@ private class GraphqlSchemaResolverClass extends ClassDeclaration {
92102
class GraphqlSchemaObjectClass extends ClassDeclaration {
93103
GraphqlSchemaObjectClass() {
94104
this.getSuperclassExpr() =
95-
graphQlSchema().getMember("Object").getASubclass().getAUse().asExpr().getExpr()
105+
graphQlSchema()
106+
.getMember("Object")
107+
.getASubclass()
108+
.getAValueReachableFromSource()
109+
.asExpr()
110+
.getExpr()
96111
}
97112

98113
/** Gets a `GraphqlFieldDefinitionMethodCall` called in this class. */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private DataFlow::LocalSourceNode trackFeature(Feature f, boolean enable, TypeTr
143143
or
144144
// Use of a constant f
145145
enable = true and
146-
result = parseOptionsModule().getMember(f.getConstantName()).getAUse()
146+
result = parseOptionsModule().getMember(f.getConstantName()).getAValueReachableFromSource()
147147
or
148148
// Treat `&`, `&=`, `|` and `|=` operators as if they preserve the on/off states
149149
// of their operands. This is an overapproximation but likely to work well in practice

ruby/ql/lib/codeql/ruby/frameworks/core/Hash.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ module Hash {
9999
HashNewSummary() { this = "Hash[]" }
100100

101101
final override ElementReference getACall() {
102-
result.getReceiver() = API::getTopLevelMember("Hash").getAUse().asExpr().getExpr() and
102+
result.getReceiver() =
103+
API::getTopLevelMember("Hash").getAValueReachableFromSource().asExpr().getExpr() and
103104
result.getNumberOfArguments() = 1
104105
}
105106

@@ -138,7 +139,8 @@ module Hash {
138139
}
139140

140141
final override ElementReference getACall() {
141-
result.getReceiver() = API::getTopLevelMember("Hash").getAUse().asExpr().getExpr() and
142+
result.getReceiver() =
143+
API::getTopLevelMember("Hash").getAValueReachableFromSource().asExpr().getExpr() and
142144
key = result.getArgument(i - 1).getConstantValue() and
143145
exists(result.getArgument(i))
144146
}

ruby/ql/lib/codeql/ruby/frameworks/http_clients/Excon.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class ExconHttpRequest extends HTTP::Client::Request::Range {
6666
override predicate disablesCertificateValidation(DataFlow::Node disablingNode) {
6767
// Check for `ssl_verify_peer: false` in the options hash.
6868
exists(DataFlow::Node arg, int i |
69-
i > 0 and arg = connectionNode.getAUse().(DataFlow::CallNode).getArgument(i)
69+
i > 0 and
70+
arg = connectionNode.getAValueReachableFromSource().(DataFlow::CallNode).getArgument(i)
7071
|
7172
argSetsVerifyPeer(arg, false, disablingNode)
7273
)
@@ -79,7 +80,8 @@ class ExconHttpRequest extends HTTP::Client::Request::Range {
7980
disableCall.asExpr().getASuccessor+() = requestUse.asExpr() and
8081
disablingNode = disableCall and
8182
not exists(DataFlow::Node arg, int i |
82-
i > 0 and arg = connectionNode.getAUse().(DataFlow::CallNode).getArgument(i)
83+
i > 0 and
84+
arg = connectionNode.getAValueReachableFromSource().(DataFlow::CallNode).getArgument(i)
8385
|
8486
argSetsVerifyPeer(arg, true, _)
8587
)

ruby/ql/lib/codeql/ruby/frameworks/http_clients/Faraday.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class FaradayHttpRequest extends HTTP::Client::Request::Range {
5858
// or
5959
// `{ ssl: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }`
6060
exists(DataFlow::Node arg, int i |
61-
i > 0 and arg = connectionNode.getAUse().(DataFlow::CallNode).getArgument(i)
61+
i > 0 and
62+
arg = connectionNode.getAValueReachableFromSource().(DataFlow::CallNode).getArgument(i)
6263
|
6364
// Either passed as an individual key:value argument, e.g.:
6465
// Faraday.new(..., ssl: {...})
@@ -132,7 +133,11 @@ private predicate isVerifyModeNonePair(CfgNodes::ExprNodes::PairCfgNode p) {
132133
key.asExpr() = p.getKey() and
133134
value.asExpr() = p.getValue() and
134135
isSymbolLiteral(key, "verify_mode") and
135-
value = API::getTopLevelMember("OpenSSL").getMember("SSL").getMember("VERIFY_NONE").getAUse()
136+
value =
137+
API::getTopLevelMember("OpenSSL")
138+
.getMember("SSL")
139+
.getMember("VERIFY_NONE")
140+
.getAValueReachableFromSource()
136141
)
137142
}
138143

ruby/ql/lib/codeql/ruby/frameworks/http_clients/HttpClient.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class HttpClientRequest extends HTTP::Client::Request::Range {
5454
// on an HTTPClient connection object `c`.
5555
disablingNode = connectionNode.getReturn("ssl_config").getReturn("verify_mode=").asSource() and
5656
disablingNode.(DataFlow::CallNode).getArgument(0) =
57-
API::getTopLevelMember("OpenSSL").getMember("SSL").getMember("VERIFY_NONE").getAUse()
57+
API::getTopLevelMember("OpenSSL")
58+
.getMember("SSL")
59+
.getMember("VERIFY_NONE")
60+
.getAValueReachableFromSource()
5861
}
5962

6063
override string getFramework() { result = "HTTPClient" }

ruby/ql/lib/codeql/ruby/frameworks/http_clients/NetHttp.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ class NetHttpRequest extends HTTP::Client::Request::Range {
7373
// foo.request(...)
7474
exists(DataFlow::CallNode setter |
7575
disablingNode =
76-
API::getTopLevelMember("OpenSSL").getMember("SSL").getMember("VERIFY_NONE").getAUse() and
76+
API::getTopLevelMember("OpenSSL")
77+
.getMember("SSL")
78+
.getMember("VERIFY_NONE")
79+
.getAValueReachableFromSource() and
7780
setter.asExpr().getExpr().(SetterMethodCall).getMethodName() = "verify_mode=" and
7881
disablingNode = setter.getArgument(0) and
7982
localFlow(setter.getReceiver(), request.getReceiver())

ruby/ql/lib/codeql/ruby/frameworks/http_clients/OpenURI.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ private predicate isSslVerifyModeNonePair(CfgNodes::ExprNodes::PairCfgNode p) {
110110
key.asExpr() = p.getKey() and
111111
value.asExpr() = p.getValue() and
112112
isSslVerifyModeLiteral(key) and
113-
value = API::getTopLevelMember("OpenSSL").getMember("SSL").getMember("VERIFY_NONE").getAUse()
113+
value =
114+
API::getTopLevelMember("OpenSSL")
115+
.getMember("SSL")
116+
.getMember("VERIFY_NONE")
117+
.getAValueReachableFromSource()
114118
)
115119
}
116120

ruby/ql/lib/codeql/ruby/frameworks/http_clients/RestClient.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class RestClientHttpRequest extends HTTP::Client::Request::Range {
5252
// `RestClient::Resource::new` takes an options hash argument, and we're
5353
// looking for `{ verify_ssl: OpenSSL::SSL::VERIFY_NONE }`.
5454
exists(DataFlow::Node arg, int i |
55-
i > 0 and arg = connectionNode.getAUse().(DataFlow::CallNode).getArgument(i)
55+
i > 0 and
56+
arg = connectionNode.getAValueReachableFromSource().(DataFlow::CallNode).getArgument(i)
5657
|
5758
// Either passed as an individual key:value argument, e.g.:
5859
// RestClient::Resource.new(..., verify_ssl: OpenSSL::SSL::VERIFY_NONE)
@@ -79,7 +80,11 @@ private predicate isVerifySslNonePair(CfgNodes::ExprNodes::PairCfgNode p) {
7980
key.asExpr() = p.getKey() and
8081
value.asExpr() = p.getValue() and
8182
isSslVerifyModeLiteral(key) and
82-
value = API::getTopLevelMember("OpenSSL").getMember("SSL").getMember("VERIFY_NONE").getAUse()
83+
value =
84+
API::getTopLevelMember("OpenSSL")
85+
.getMember("SSL")
86+
.getMember("VERIFY_NONE")
87+
.getAValueReachableFromSource()
8388
)
8489
}
8590

ruby/ql/test/library-tests/dataflow/api-graphs/use.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ApiUseTest extends InlineExpectationsTest {
2626
l = n.getLocation() and
2727
(
2828
tag = "use" and
29-
n = a.getAUse()
29+
n = a.getAValueReachableFromSource()
3030
or
3131
tag = "def" and
3232
n = a.getARhs()

0 commit comments

Comments
 (0)