Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 71dbb24

Browse files
committed
Move existing Regexp module to stdlib
1 parent 7f3a911 commit 71dbb24

2 files changed

Lines changed: 61 additions & 64 deletions

File tree

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -606,70 +606,6 @@ module URL {
606606
}
607607
}
608608

609-
/** Provides models of commonly used APIs in the `regexp` package. */
610-
module Regexp {
611-
private class Pattern extends RegexpPattern::Range, DataFlow::ArgumentNode {
612-
string fnName;
613-
614-
Pattern() {
615-
exists(Function fn | fnName.matches("Match%") or fnName.matches("%Compile%") |
616-
fn.hasQualifiedName("regexp", fnName) and
617-
this = fn.getACall().getArgument(0)
618-
)
619-
}
620-
621-
override DataFlow::Node getAParse() { result = this.getCall() }
622-
623-
override string getPattern() { result = this.asExpr().getStringValue() }
624-
625-
override DataFlow::Node getAUse() {
626-
fnName.matches("MustCompile%") and
627-
result = this.getCall().getASuccessor*()
628-
or
629-
fnName.matches("Compile%") and
630-
result = this.getCall().getResult(0).getASuccessor*()
631-
or
632-
result = this
633-
}
634-
}
635-
636-
private class MatchFunction extends RegexpMatchFunction::Range, Function {
637-
MatchFunction() {
638-
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", fn))
639-
}
640-
641-
override FunctionInput getRegexpArg() { result.isParameter(0) }
642-
643-
override FunctionInput getValue() { result.isParameter(1) }
644-
645-
override FunctionOutput getResult() { result.isResult(0) }
646-
}
647-
648-
private class MatchMethod extends RegexpMatchFunction::Range, Method {
649-
MatchMethod() {
650-
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", "Regexp", fn))
651-
}
652-
653-
override FunctionInput getRegexpArg() { result.isReceiver() }
654-
655-
override FunctionInput getValue() { result.isParameter(0) }
656-
657-
override FunctionOutput getResult() { result.isResult() }
658-
}
659-
660-
private class ReplaceFunction extends RegexpReplaceFunction::Range, Method {
661-
ReplaceFunction() {
662-
exists(string fn | fn.matches("ReplaceAll%") | this.hasQualifiedName("regexp", "Regexp", fn))
663-
}
664-
665-
override FunctionInput getRegexpArg() { result.isReceiver() }
666-
667-
override FunctionInput getSource() { result.isParameter(0) }
668-
669-
override FunctionOutput getResult() { result.isResult() }
670-
}
671-
}
672-
673609
/** Provides models of commonly used functions in the `log` package. */
674610
module Log {
675611
private class LogCall extends LoggerCall::Range, DataFlow::CallNode {

ql/src/semmle/go/frameworks/stdlib/Regexp.qll

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,67 @@ import go
66

77
/** Provides models of commonly used functions in the `regexp` package. */
88
module Regexp {
9+
private class Pattern extends RegexpPattern::Range, DataFlow::ArgumentNode {
10+
string fnName;
11+
12+
Pattern() {
13+
exists(Function fn | fnName.matches("Match%") or fnName.matches("%Compile%") |
14+
fn.hasQualifiedName("regexp", fnName) and
15+
this = fn.getACall().getArgument(0)
16+
)
17+
}
18+
19+
override DataFlow::Node getAParse() { result = this.getCall() }
20+
21+
override string getPattern() { result = this.asExpr().getStringValue() }
22+
23+
override DataFlow::Node getAUse() {
24+
fnName.matches("MustCompile%") and
25+
result = this.getCall().getASuccessor*()
26+
or
27+
fnName.matches("Compile%") and
28+
result = this.getCall().getResult(0).getASuccessor*()
29+
or
30+
result = this
31+
}
32+
}
33+
34+
private class MatchFunction extends RegexpMatchFunction::Range, Function {
35+
MatchFunction() {
36+
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", fn))
37+
}
38+
39+
override FunctionInput getRegexpArg() { result.isParameter(0) }
40+
41+
override FunctionInput getValue() { result.isParameter(1) }
42+
43+
override FunctionOutput getResult() { result.isResult(0) }
44+
}
45+
46+
private class MatchMethod extends RegexpMatchFunction::Range, Method {
47+
MatchMethod() {
48+
exists(string fn | fn.matches("Match%") | this.hasQualifiedName("regexp", "Regexp", fn))
49+
}
50+
51+
override FunctionInput getRegexpArg() { result.isReceiver() }
52+
53+
override FunctionInput getValue() { result.isParameter(0) }
54+
55+
override FunctionOutput getResult() { result.isResult() }
56+
}
57+
58+
private class ReplaceFunction extends RegexpReplaceFunction::Range, Method {
59+
ReplaceFunction() {
60+
exists(string fn | fn.matches("ReplaceAll%") | this.hasQualifiedName("regexp", "Regexp", fn))
61+
}
62+
63+
override FunctionInput getRegexpArg() { result.isReceiver() }
64+
65+
override FunctionInput getSource() { result.isParameter(0) }
66+
67+
override FunctionOutput getResult() { result.isResult() }
68+
}
69+
970
private class FunctionModels extends TaintTracking::FunctionModel {
1071
FunctionInput inp;
1172
FunctionOutput outp;

0 commit comments

Comments
 (0)