Move existing Regexp module to stdlib

This commit is contained in:
Slavomir
2020-09-12 12:12:04 +02:00
parent 7f3a911f86
commit 71dbb244f9
2 changed files with 61 additions and 64 deletions

View File

@@ -606,70 +606,6 @@ module URL {
}
}
/** Provides models of commonly used APIs in the `regexp` package. */
module Regexp {
private class Pattern extends RegexpPattern::Range, DataFlow::ArgumentNode {
string fnName;
Pattern() {
exists(Function fn | fnName.matches("Match%") or fnName.matches("%Compile%") |
fn.hasQualifiedName("regexp", fnName) and
this = fn.getACall().getArgument(0)
)
}
override DataFlow::Node getAParse() { result = this.getCall() }
override string getPattern() { result = this.asExpr().getStringValue() }
override DataFlow::Node getAUse() {
fnName.matches("MustCompile%") and
result = this.getCall().getASuccessor*()
or
fnName.matches("Compile%") and
result = this.getCall().getResult(0).getASuccessor*()
or
result = this
}
}
private class MatchFunction extends RegexpMatchFunction::Range, Function {
MatchFunction() {
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", fn))
}
override FunctionInput getRegexpArg() { result.isParameter(0) }
override FunctionInput getValue() { result.isParameter(1) }
override FunctionOutput getResult() { result.isResult(0) }
}
private class MatchMethod extends RegexpMatchFunction::Range, Method {
MatchMethod() {
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", "Regexp", fn))
}
override FunctionInput getRegexpArg() { result.isReceiver() }
override FunctionInput getValue() { result.isParameter(0) }
override FunctionOutput getResult() { result.isResult() }
}
private class ReplaceFunction extends RegexpReplaceFunction::Range, Method {
ReplaceFunction() {
exists(string fn | fn.matches("ReplaceAll%") | this.hasQualifiedName("regexp", "Regexp", fn))
}
override FunctionInput getRegexpArg() { result.isReceiver() }
override FunctionInput getSource() { result.isParameter(0) }
override FunctionOutput getResult() { result.isResult() }
}
}
/** Provides models of commonly used functions in the `log` package. */
module Log {
private class LogCall extends LoggerCall::Range, DataFlow::CallNode {

View File

@@ -6,6 +6,67 @@ import go
/** Provides models of commonly used functions in the `regexp` package. */
module Regexp {
private class Pattern extends RegexpPattern::Range, DataFlow::ArgumentNode {
string fnName;
Pattern() {
exists(Function fn | fnName.matches("Match%") or fnName.matches("%Compile%") |
fn.hasQualifiedName("regexp", fnName) and
this = fn.getACall().getArgument(0)
)
}
override DataFlow::Node getAParse() { result = this.getCall() }
override string getPattern() { result = this.asExpr().getStringValue() }
override DataFlow::Node getAUse() {
fnName.matches("MustCompile%") and
result = this.getCall().getASuccessor*()
or
fnName.matches("Compile%") and
result = this.getCall().getResult(0).getASuccessor*()
or
result = this
}
}
private class MatchFunction extends RegexpMatchFunction::Range, Function {
MatchFunction() {
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", fn))
}
override FunctionInput getRegexpArg() { result.isParameter(0) }
override FunctionInput getValue() { result.isParameter(1) }
override FunctionOutput getResult() { result.isResult(0) }
}
private class MatchMethod extends RegexpMatchFunction::Range, Method {
MatchMethod() {
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", "Regexp", fn))
}
override FunctionInput getRegexpArg() { result.isReceiver() }
override FunctionInput getValue() { result.isParameter(0) }
override FunctionOutput getResult() { result.isResult() }
}
private class ReplaceFunction extends RegexpReplaceFunction::Range, Method {
ReplaceFunction() {
exists(string fn | fn.matches("ReplaceAll%") | this.hasQualifiedName("regexp", "Regexp", fn))
}
override FunctionInput getRegexpArg() { result.isReceiver() }
override FunctionInput getSource() { result.isParameter(0) }
override FunctionOutput getResult() { result.isResult() }
}
private class FunctionModels extends TaintTracking::FunctionModel {
FunctionInput inp;
FunctionOutput outp;