Ruby: Rename getAnImmediateUse -> asSource

This commit is contained in:
Asger F
2022-05-30 13:25:50 +02:00
parent f2403e2610
commit 573c5c5efe
11 changed files with 17 additions and 24 deletions

View File

@@ -111,7 +111,7 @@ module API {
* Unlike `getAUse()`, this predicate only gets the immediate references, not the indirect uses
* found via data flow.
*/
DataFlow::LocalSourceNode getAnImmediateUse() { Impl::use(this, result) }
DataFlow::LocalSourceNode asSource() { Impl::use(this, result) }
/**
* Gets a data-flow node corresponding the value flowing into this API component.
@@ -126,9 +126,7 @@ module API {
/**
* Gets a call to a method on the receiver represented by this API component.
*/
DataFlow::CallNode getAMethodCall(string method) {
result = this.getReturn(method).getAnImmediateUse()
}
DataFlow::CallNode getAMethodCall(string method) { result = this.getReturn(method).asSource() }
/**
* Gets a node representing member `m` of this API component.
@@ -203,7 +201,7 @@ module API {
/**
* Gets a `new` call to the function represented by this API component.
*/
DataFlow::ExprNode getAnInstantiation() { result = this.getInstance().getAnImmediateUse() }
DataFlow::ExprNode getAnInstantiation() { result = this.getInstance().asSource() }
/**
* Gets a node representing a (direct or indirect) subclass of the class represented by this node.

View File

@@ -63,11 +63,7 @@ private module Config {
)
or
// `Rails.application.config`
this =
API::getTopLevelMember("Rails")
.getReturn("application")
.getReturn("config")
.getAnImmediateUse()
this = API::getTopLevelMember("Rails").getReturn("application").getReturn("config").asSource()
or
// `Rails.application.configure { ... config ... }`
// `Rails::Application.configure { ... config ... }`

View File

@@ -25,7 +25,7 @@ private import codeql.ruby.dataflow.RemoteFlowSources
* A remote flow source originating from a CSV source row.
*/
private class RemoteFlowSourceFromCsv extends RemoteFlowSource::Range {
RemoteFlowSourceFromCsv() { this = ModelOutput::getASourceNode("remote").getAnImmediateUse() }
RemoteFlowSourceFromCsv() { this = ModelOutput::getASourceNode("remote").asSource() }
override string getSourceType() { result = "Remote flow (from model)" }
}

View File

@@ -30,8 +30,8 @@ class ExconHttpRequest extends HTTP::Client::Request::Range {
DataFlow::Node connectionUse;
ExconHttpRequest() {
requestUse = requestNode.getAnImmediateUse() and
connectionUse = connectionNode.getAnImmediateUse() and
requestUse = requestNode.asSource() and
connectionUse = connectionNode.asSource() and
connectionNode =
[
// one-off requests

View File

@@ -38,8 +38,8 @@ class FaradayHttpRequest extends HTTP::Client::Request::Range {
] and
requestNode =
connectionNode.getReturn(["get", "head", "delete", "post", "put", "patch", "trace"]) and
requestUse = requestNode.getAnImmediateUse() and
connectionUse = connectionNode.getAnImmediateUse() and
requestUse = requestNode.asSource() and
connectionUse = connectionNode.asSource() and
this = requestUse.asExpr().getExpr()
}

View File

@@ -29,7 +29,7 @@ class HttpClientRequest extends HTTP::Client::Request::Range {
API::getTopLevelMember("HTTPClient").getInstance()
] and
requestNode = connectionNode.getReturn(method) and
requestUse = requestNode.getAnImmediateUse() and
requestUse = requestNode.asSource() and
method in [
"get", "head", "delete", "options", "post", "put", "trace", "get_content", "post_content"
] and
@@ -52,8 +52,7 @@ class HttpClientRequest extends HTTP::Client::Request::Range {
// Look for calls to set
// `c.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE`
// on an HTTPClient connection object `c`.
disablingNode =
connectionNode.getReturn("ssl_config").getReturn("verify_mode=").getAnImmediateUse() and
disablingNode = connectionNode.getReturn("ssl_config").getReturn("verify_mode=").asSource() and
disablingNode.(DataFlow::CallNode).getArgument(0) =
API::getTopLevelMember("OpenSSL").getMember("SSL").getMember("VERIFY_NONE").getAUse()
}

View File

@@ -28,7 +28,7 @@ class HttpartyRequest extends HTTP::Client::Request::Range {
DataFlow::CallNode requestUse;
HttpartyRequest() {
requestUse = requestNode.getAnImmediateUse() and
requestUse = requestNode.asSource() and
requestNode =
API::getTopLevelMember("HTTParty")
.getReturn(["get", "head", "delete", "options", "post", "put", "patch"]) and

View File

@@ -25,7 +25,7 @@ class NetHttpRequest extends HTTP::Client::Request::Range {
NetHttpRequest() {
exists(string method |
request = requestNode.getAnImmediateUse() and
request = requestNode.asSource() and
this = request.asExpr().getExpr()
|
// Net::HTTP.get(...)
@@ -59,7 +59,7 @@ class NetHttpRequest extends HTTP::Client::Request::Range {
new = API::getTopLevelMember("Net").getMember("HTTP").getInstance() and
requestNode = new.getReturn(_)
|
result = new.getAnImmediateUse().(DataFlow::CallNode).getArgument(0)
result = new.asSource().(DataFlow::CallNode).getArgument(0)
)
}

View File

@@ -28,7 +28,7 @@ class OpenUriRequest extends HTTP::Client::Request::Range {
[API::getTopLevelMember("URI"), API::getTopLevelMember("URI").getReturn("parse")]
.getReturn("open"), API::getTopLevelMember("OpenURI").getReturn("open_uri")
] and
requestUse = requestNode.getAnImmediateUse() and
requestUse = requestNode.asSource() and
this = requestUse.asExpr().getExpr()
}

View File

@@ -22,7 +22,7 @@ class RestClientHttpRequest extends HTTP::Client::Request::Range {
API::Node connectionNode;
RestClientHttpRequest() {
requestUse = requestNode.getAnImmediateUse() and
requestUse = requestNode.asSource() and
this = requestUse.asExpr().getExpr() and
(
connectionNode =

View File

@@ -19,7 +19,7 @@ class TyphoeusHttpRequest extends HTTP::Client::Request::Range {
API::Node requestNode;
TyphoeusHttpRequest() {
requestUse = requestNode.getAnImmediateUse() and
requestUse = requestNode.asSource() and
requestNode =
API::getTopLevelMember("Typhoeus")
.getReturn(["get", "head", "delete", "options", "post", "put", "patch"]) and