Go: Rewrite `::Range` patterns to use `instanceof`

This commit is contained in:
Rasmus Wriedt Larsen 2022-09-13 15:43:06 +02:00
Родитель 6f5701f9c7
Коммит ca66a29b18
Не найден ключ, соответствующий данной подписи
11 изменённых файлов: 53 добавлений и 141 удалений

Просмотреть файл

@ -12,20 +12,16 @@ module StringOps {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `StringOps::HasPrefix::Range` instead.
*/
class HasPrefix extends DataFlow::Node {
HasPrefix::Range range;
HasPrefix() { range = this }
class HasPrefix extends DataFlow::Node instanceof HasPrefix::Range {
/**
* Gets the `A` in `strings.HasPrefix(A, B)`.
*/
DataFlow::Node getBaseString() { result = range.getBaseString() }
DataFlow::Node getBaseString() { result = super.getBaseString() }
/**
* Gets the `B` in `strings.HasPrefix(A, B)`.
*/
DataFlow::Node getSubstring() { result = range.getSubstring() }
DataFlow::Node getSubstring() { result = super.getSubstring() }
/**
* Gets the polarity of the check.
@ -33,7 +29,7 @@ module StringOps {
* If the polarity is `false` the check returns `true` if the string does not start
* with the given substring.
*/
boolean getPolarity() { result = range.getPolarity() }
boolean getPolarity() { result = super.getPolarity() }
}
class StartsWith = HasPrefix;
@ -241,25 +237,21 @@ module StringOps {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `StringOps::Concatenation::Range` instead.
*/
class Concatenation extends DataFlow::Node {
Concatenation::Range self;
Concatenation() { this = self }
class Concatenation extends DataFlow::Node instanceof Concatenation::Range {
/**
* Gets the `n`th operand of this string concatenation, if there is a data-flow node for it.
*/
DataFlow::Node getOperand(int n) { result = self.getOperand(n) }
DataFlow::Node getOperand(int n) { result = super.getOperand(n) }
/**
* Gets the string value of the `n`th operand of this string concatenation, if it is a constant.
*/
string getOperandStringValue(int n) { result = self.getOperandStringValue(n) }
string getOperandStringValue(int n) { result = super.getOperandStringValue(n) }
/**
* Gets the number of operands of this string concatenation.
*/
int getNumOperand() { result = self.getNumOperand() }
int getNumOperand() { result = super.getNumOperand() }
}
/** Provides predicates and classes for working with string concatenations. */

Просмотреть файл

@ -43,8 +43,4 @@ module GeneratedFile {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `GeneratedFile::Range` instead.
*/
class GeneratedFile extends File {
GeneratedFile::Range self;
GeneratedFile() { this = self }
}
class GeneratedFile extends File instanceof GeneratedFile::Range { }

Просмотреть файл

@ -31,11 +31,7 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::ResponseWriter::Range` instead.
*/
class ResponseWriter extends Variable {
ResponseWriter::Range self;
ResponseWriter() { this = self }
class ResponseWriter extends Variable instanceof ResponseWriter::Range {
/** Gets the body that is written in this HTTP response. */
ResponseBody getBody() { result.getResponseWriter() = this }
@ -47,8 +43,8 @@ module HTTP {
/** Gets a data-flow node that is a use of this response writer. */
DataFlow::Node getANode() {
result = self.getANode() or
result.(DataFlow::PostUpdateNode).getPreUpdateNode() = self.getANode()
result = super.getANode() or
result.(DataFlow::PostUpdateNode).getPreUpdateNode() = super.getANode()
}
}
@ -100,19 +96,15 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::HeaderWrite::Range` instead.
*/
class HeaderWrite extends DataFlow::ExprNode {
HeaderWrite::Range self;
HeaderWrite() { this = self }
class HeaderWrite extends DataFlow::ExprNode instanceof HeaderWrite::Range {
/** Gets the (lower-case) name of a header set by this definition. */
string getHeaderName() { result = self.getHeaderName() }
string getHeaderName() { result = super.getHeaderName() }
/** Gets the value of the header set by this definition. */
string getHeaderValue() { result = self.getHeaderValue() }
string getHeaderValue() { result = super.getHeaderValue() }
/** Holds if this header write defines the header `header`. */
predicate definesHeader(string header, string value) { self.definesHeader(header, value) }
predicate definesHeader(string header, string value) { super.definesHeader(header, value) }
/**
* Gets the node representing the name of the header defined by this write.
@ -121,13 +113,13 @@ module HTTP {
* sets the `Content-Type` header) may not have such a node, so callers should use
* `getHeaderName` in preference to this method).
*/
DataFlow::Node getName() { result = self.getName() }
DataFlow::Node getName() { result = super.getName() }
/** Gets the node representing the value of the header defined by this write. */
DataFlow::Node getValue() { result = self.getValue() }
DataFlow::Node getValue() { result = super.getValue() }
/** Gets the response writer associated with this header write, if any. */
ResponseWriter getResponseWriter() { result = self.getResponseWriter() }
ResponseWriter getResponseWriter() { result = super.getResponseWriter() }
}
/** A data-flow node whose value is written to an HTTP header. */
@ -171,11 +163,7 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::RequestBody::Range` instead.
*/
class RequestBody extends DataFlow::Node {
RequestBody::Range self;
RequestBody() { this = self }
}
class RequestBody extends DataFlow::Node instanceof RequestBody::Range { }
/** Provides a class for modeling new HTTP response-body APIs. */
module ResponseBody {
@ -215,19 +203,15 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::ResponseBody::Range` instead.
*/
class ResponseBody extends DataFlow::Node {
ResponseBody::Range self;
ResponseBody() { this = self }
class ResponseBody extends DataFlow::Node instanceof ResponseBody::Range {
/** Gets the response writer associated with this header write, if any. */
ResponseWriter getResponseWriter() { result = self.getResponseWriter() }
ResponseWriter getResponseWriter() { result = super.getResponseWriter() }
/** Gets a content-type associated with this body. */
string getAContentType() { result = self.getAContentType() }
string getAContentType() { result = super.getAContentType() }
/** Gets a dataflow node for a content-type associated with this body. */
DataFlow::Node getAContentTypeNode() { result = self.getAContentTypeNode() }
DataFlow::Node getAContentTypeNode() { result = super.getAContentTypeNode() }
}
/** Provides a class for modeling new HTTP template response-body APIs. */
@ -250,13 +234,9 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::TemplateResponseBody::Range` instead.
*/
class TemplateResponseBody extends ResponseBody {
override TemplateResponseBody::Range self;
TemplateResponseBody() { this = self }
class TemplateResponseBody extends ResponseBody instanceof TemplateResponseBody::Range {
/** Gets the read of the variable inside the template where this value is read. */
HtmlTemplate::TemplateRead getRead() { result = self.getRead() }
HtmlTemplate::TemplateRead getRead() { result = super.getRead() }
}
/** Provides a class for modeling new HTTP client request APIs. */
@ -285,15 +265,11 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::ClientRequest::Range` instead.
*/
class ClientRequest extends DataFlow::Node {
ClientRequest::Range self;
ClientRequest() { this = self }
class ClientRequest extends DataFlow::Node instanceof ClientRequest::Range {
/**
* Gets the URL of the request.
*/
DataFlow::Node getUrl() { result = self.getUrl() }
DataFlow::Node getUrl() { result = super.getUrl() }
}
/** Provides a class for modeling new HTTP redirect APIs. */
@ -337,16 +313,12 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::Redirect::Range` instead.
*/
class Redirect extends DataFlow::Node {
Redirect::Range self;
Redirect() { this = self }
class Redirect extends DataFlow::Node instanceof Redirect::Range {
/** Gets the data-flow node representing the URL being redirected to. */
DataFlow::Node getUrl() { result = self.getUrl() }
DataFlow::Node getUrl() { result = super.getUrl() }
/** Gets the response writer that this redirect is sent on, if any. */
ResponseWriter getResponseWriter() { result = self.getResponseWriter() }
ResponseWriter getResponseWriter() { result = super.getResponseWriter() }
}
/** Provides a class for modeling new HTTP handler APIs. */
@ -369,12 +341,8 @@ module HTTP {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `HTTP::RequestHandler::Range` instead.
*/
class RequestHandler extends DataFlow::Node {
RequestHandler::Range self;
RequestHandler() { this = self }
class RequestHandler extends DataFlow::Node instanceof RequestHandler::Range {
/** Gets a node that is used in a check that is tested before this handler is run. */
predicate guardedBy(DataFlow::Node check) { self.guardedBy(check) }
predicate guardedBy(DataFlow::Node check) { super.guardedBy(check) }
}
}

Просмотреть файл

@ -341,13 +341,9 @@ module Public {
}
/** A function, viewed as a node in a data flow graph. */
class FunctionNode extends Node {
FunctionNode::Range self;
FunctionNode() { this = self }
class FunctionNode extends Node instanceof FunctionNode::Range {
/** Gets the `i`th parameter of this function. */
ParameterNode getParameter(int i) { result = self.getParameter(i) }
ParameterNode getParameter(int i) { result = super.getParameter(i) }
/** Gets a parameter of this function. */
ParameterNode getAParameter() { result = this.getParameter(_) }
@ -356,18 +352,18 @@ module Public {
int getNumParameter() { result = count(this.getAParameter()) }
/** Gets the name of this function, if it has one. */
string getName() { result = self.getName() }
string getName() { result = super.getName() }
/**
* Gets the dataflow node holding the value of the receiver, if any.
*/
ReceiverNode getReceiver() { result = self.getReceiver() }
ReceiverNode getReceiver() { result = super.getReceiver() }
/**
* Gets a value returned by the given function via a return statement or an assignment to a
* result variable.
*/
ResultNode getAResult() { result = self.getAResult() }
ResultNode getAResult() { result = super.getAResult() }
/**
* Gets the data-flow node corresponding to the `i`th result of this function.
@ -379,7 +375,7 @@ module Public {
*
* Note that this predicate has no result for function literals.
*/
Function getFunction() { result = self.getFunction() }
Function getFunction() { result = super.getFunction() }
}
/** A representation of a function that is declared in the module scope. */

Просмотреть файл

@ -9,11 +9,7 @@ import go
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `EmailData::Range` instead.
*/
class EmailData extends DataFlow::Node {
EmailData::Range self;
EmailData() { this = self }
}
class EmailData extends DataFlow::Node instanceof EmailData::Range { }
/** Provides classes for working with data that is incorporated into an email. */
module EmailData {

Просмотреть файл

@ -12,11 +12,7 @@ module NoSql {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `NoSQL::Query::Range` instead.
*/
class Query extends DataFlow::Node {
Query::Range self;
Query() { this = self }
}
class Query extends DataFlow::Node instanceof Query::Range { }
/** Provides classes for working with NoSql queries. */
module Query {

Просмотреть файл

@ -12,13 +12,9 @@ module SQL {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `SQL::Query::Range` instead.
*/
class Query extends DataFlow::Node {
Query::Range self;
Query() { this = self }
class Query extends DataFlow::Node instanceof Query::Range {
/** Gets a result of this query execution. */
DataFlow::Node getAResult() { result = self.getAResult() }
DataFlow::Node getAResult() { result = super.getAResult() }
/**
* Gets a query string that is used as (part of) this SQL query.
@ -26,7 +22,7 @@ module SQL {
* Note that this may not resolve all `QueryString`s that should be associated with this
* query due to data flow.
*/
QueryString getAQueryString() { result = self.getAQueryString() }
QueryString getAQueryString() { result = super.getAQueryString() }
}
/**
@ -59,11 +55,7 @@ module SQL {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `SQL::QueryString::Range` instead.
*/
class QueryString extends DataFlow::Node {
QueryString::Range self;
QueryString() { this = self }
}
class QueryString extends DataFlow::Node instanceof QueryString::Range { }
/** Provides classes for working with SQL query strings. */
module QueryString {

Просмотреть файл

@ -8,11 +8,7 @@ import go
* Extend this class to refine existing models of testing frameworks. If you want to model new
* frameworks, extend `TestCase::Range` instead.
*/
class TestCase extends AstNode {
TestCase::Range self;
TestCase() { this = self }
}
class TestCase extends AstNode instanceof TestCase::Range { }
/** Provides classes for working with test cases. */
module TestCase {
@ -47,11 +43,7 @@ module TestCase {
* Extend this class to refine existing models of testing frameworks. If you want to model new
* frameworks, extend `TestFile::Range` instead.
*/
class TestFile extends File {
TestFile::Range self;
TestFile() { this = self }
}
class TestFile extends File instanceof TestFile::Range { }
/** Provides classes for working with test files. */
module TestFile {

Просмотреть файл

@ -8,13 +8,9 @@ import go
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `WebSocketRequestCall::Range` instead.
*/
class WebSocketRequestCall extends DataFlow::CallNode {
WebSocketRequestCall::Range self;
WebSocketRequestCall() { this = self }
class WebSocketRequestCall extends DataFlow::CallNode instanceof WebSocketRequestCall::Range {
/** Gets the URL of the request. */
DataFlow::Node getRequestUrl() { result = self.getRequestUrl() }
DataFlow::Node getRequestUrl() { result = super.getRequestUrl() }
}
/** Provides classes for working with WebSocket request functions. */
@ -143,13 +139,9 @@ class WebSocketReaderAsSource extends UntrustedFlowSource::Range {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `WebSocketReader::Range` instead.
*/
class WebSocketReader extends Function {
WebSocketReader::Range self;
WebSocketReader() { this = self }
class WebSocketReader extends Function instanceof WebSocketReader::Range {
/** Gets an output of this function containing data that is read from a WebSocket connection. */
FunctionOutput getAnOutput() { result = self.getAnOutput() }
FunctionOutput getAnOutput() { result = super.getAnOutput() }
}
/** Provides classes for working with messages read from a WebSocket. */

Просмотреть файл

@ -12,11 +12,7 @@ module XPath {
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `XPath::XPathExpressionString::Range` instead.
*/
class XPathExpressionString extends DataFlow::Node {
XPathExpressionString::Range self;
XPathExpressionString() { this = self }
}
class XPathExpressionString extends DataFlow::Node instanceof XPathExpressionString::Range { }
/** Provides classes for working with XPath expression strings. */
module XPathExpressionString {

Просмотреть файл

@ -11,11 +11,7 @@ private import semmle.go.dataflow.ExternalFlow as ExternalFlow
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `UntrustedFlowSource::Range` instead.
*/
class UntrustedFlowSource extends DataFlow::Node {
UntrustedFlowSource::Range self;
UntrustedFlowSource() { this = self }
}
class UntrustedFlowSource extends DataFlow::Node instanceof UntrustedFlowSource::Range { }
/** Provides a class for modeling new sources of untrusted data. */
module UntrustedFlowSource {