Skip to content

Commit 7a25200

Browse files
committed
Remove fields which are only used in char pred
1 parent a113b8e commit 7a25200

File tree

8 files changed

+45
-61
lines changed

8 files changed

+45
-61
lines changed

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ module Private {
6161
/** A data flow node that represents the output of a call. */
6262
class OutNode extends Node {
6363
DataFlow::CallNode call;
64-
int i;
6564

66-
OutNode() { this = call.getResult(i) }
65+
OutNode() { this = call.getResult(_) }
6766

6867
/** Gets the underlying call. */
6968
DataFlowCall getCall() { result = call.asExpr() }
@@ -753,13 +752,14 @@ module Public {
753752
* of the function.
754753
*/
755754
class ResultNode extends InstructionNode {
756-
FuncDef fd;
757755
int i;
758756

759757
ResultNode() {
760-
exists(IR::ReturnInstruction ret | ret.getRoot() = fd | insn = ret.getResult(i))
761-
or
762-
insn.(IR::ReadResultInstruction).reads(fd.getResultVar(i))
758+
exists(FuncDef fd |
759+
exists(IR::ReturnInstruction ret | ret.getRoot() = fd | insn = ret.getResult(i))
760+
or
761+
insn.(IR::ReadResultInstruction).reads(fd.getResultVar(i))
762+
)
763763
}
764764

765765
/** Gets the index of this result among all results of the function. */
@@ -1112,12 +1112,12 @@ module Public {
11121112
*/
11131113
class RangeElementNode extends Node {
11141114
DataFlow::Node base;
1115-
IR::ExtractTupleElementInstruction extract;
11161115

11171116
RangeElementNode() {
1118-
this.asInstruction() = extract and
1119-
extract.extractsElement(_, 1) and
1120-
extract.getBase().(IR::GetNextEntryInstruction).getDomain() = base.asInstruction()
1117+
exists(IR::ExtractTupleElementInstruction extract | extract = this.asInstruction() |
1118+
extract.extractsElement(_, 1) and
1119+
extract.getBase().(IR::GetNextEntryInstruction).getDomain() = base.asInstruction()
1120+
)
11211121
}
11221122

11231123
/** Gets the data-flow node representing the base from which the element is read. */

go/ql/lib/semmle/go/frameworks/Beego.qll

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ module Beego {
5151
*/
5252
private class BeegoInputSource extends UntrustedFlowSource::Range {
5353
string methodName;
54-
FunctionOutput output;
5554

5655
BeegoInputSource() {
57-
exists(DataFlow::MethodCallNode c | this = output.getExitNode(c) |
58-
c.getTarget().hasQualifiedName(contextPackagePath(), "BeegoInput", methodName)
59-
) and
60-
(
56+
exists(FunctionOutput output |
6157
methodName = "Bind" and
6258
output.isParameter(0)
6359
or
@@ -66,6 +62,10 @@ module Beego {
6662
"URI", "URL", "UserAgent"
6763
] and
6864
output.isResult(0)
65+
|
66+
exists(DataFlow::MethodCallNode c | this = output.getExitNode(c) |
67+
c.getTarget().hasQualifiedName(contextPackagePath(), "BeegoInput", methodName)
68+
)
6969
)
7070
}
7171

@@ -81,16 +81,8 @@ module Beego {
8181
* `beego.Controller` sources of untrusted data.
8282
*/
8383
private class BeegoControllerSource extends UntrustedFlowSource::Range {
84-
string methodName;
85-
FunctionOutput output;
86-
8784
BeegoControllerSource() {
88-
exists(DataFlow::MethodCallNode c |
89-
c.getTarget().hasQualifiedName(packagePath(), "Controller", methodName)
90-
|
91-
this = output.getExitNode(c)
92-
) and
93-
(
85+
exists(string methodName, FunctionOutput output |
9486
methodName = "ParseForm" and
9587
output.isParameter(0)
9688
or
@@ -99,6 +91,12 @@ module Beego {
9991
or
10092
methodName = "GetFile" and
10193
output.isResult(1)
94+
|
95+
exists(DataFlow::MethodCallNode c |
96+
c.getTarget().hasQualifiedName(packagePath(), "Controller", methodName)
97+
|
98+
this = output.getExitNode(c)
99+
)
102100
)
103101
}
104102
}
@@ -225,10 +223,8 @@ module Beego {
225223
}
226224

227225
private class ContextResponseBody extends Http::ResponseBody::Range {
228-
string name;
229-
230226
ContextResponseBody() {
231-
exists(Method m | m.hasQualifiedName(contextPackagePath(), "Context", name) |
227+
exists(Method m, string name | m.hasQualifiedName(contextPackagePath(), "Context", name) |
232228
name = "Abort" and this = m.getACall().getArgument(1)
233229
or
234230
name = "WriteString" and this = m.getACall().getArgument(0)
@@ -326,16 +322,17 @@ module Beego {
326322
}
327323

328324
private class RedirectMethods extends Http::Redirect::Range, DataFlow::CallNode {
329-
string package;
330325
string className;
331326

332327
RedirectMethods() {
333-
(
334-
package = packagePath() and className = "Controller"
335-
or
336-
package = contextPackagePath() and className = "Context"
337-
) and
338-
this = any(Method m | m.hasQualifiedName(package, className, "Redirect")).getACall()
328+
exists(string package |
329+
(
330+
package = packagePath() and className = "Controller"
331+
or
332+
package = contextPackagePath() and className = "Context"
333+
) and
334+
this = any(Method m | m.hasQualifiedName(package, className, "Redirect")).getACall()
335+
)
339336
}
340337

341338
override DataFlow::Node getUrl() {

go/ql/lib/semmle/go/frameworks/Echo.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ private module Echo {
4343
* Models of `Context.Get/Set`. `Context` behaves like a map, with corresponding taint propagation.
4444
*/
4545
private class ContextMapModels extends TaintTracking::FunctionModel, Method {
46-
string methodName;
4746
FunctionInput input;
4847
FunctionOutput output;
4948

5049
ContextMapModels() {
51-
(
50+
exists(string methodName | this.hasQualifiedName(packagePath(), "Context", methodName) |
5251
methodName = "Get" and input.isReceiver() and output.isResult()
5352
or
5453
methodName = "Set" and input.isParameter(1) and output.isReceiver()
55-
) and
56-
this.hasQualifiedName(packagePath(), "Context", methodName)
54+
)
5755
}
5856

5957
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {

go/ql/lib/semmle/go/frameworks/K8sIoApiCoreV1.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ module K8sIoApiCoreV1 {
1010
string packagePath() { result = package("k8s.io/api", "core/v1") }
1111

1212
private class SecretDeepCopy extends TaintTracking::FunctionModel, Method {
13-
string methodName;
1413
FunctionOutput output;
1514

1615
SecretDeepCopy() {
17-
(
16+
exists(string methodName |
1817
methodName in ["DeepCopy", "DeepCopyObject"] and output.isResult()
1918
or
2019
methodName = "DeepCopyInto" and output.isParameter(0)
21-
) and
22-
this.hasQualifiedName(packagePath(), ["Secret", "SecretList"], methodName)
20+
|
21+
this.hasQualifiedName(packagePath(), ["Secret", "SecretList"], methodName)
22+
)
2323
}
2424

2525
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {

go/ql/lib/semmle/go/frameworks/Revel.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,9 @@ module Revel {
201201
private class RevelHeaderMethods extends TaintTracking::FunctionModel {
202202
FunctionInput input;
203203
FunctionOutput output;
204-
string name;
205204

206205
RevelHeaderMethods() {
207-
this.(Method).hasQualifiedName(packagePath(), "RevelHeader", name) and
208-
(
206+
exists(string name | this.(Method).hasQualifiedName(packagePath(), "RevelHeader", name) |
209207
name = ["Add", "Set"] and input.isParameter([0, 1]) and output.isReceiver()
210208
or
211209
name = ["Get", "GetAll"] and input.isReceiver() and output.isResult()

go/ql/lib/semmle/go/frameworks/stdlib/NetHttp.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ module NetHttp {
5757
}
5858

5959
private class MapWrite extends Http::HeaderWrite::Range, DataFlow::Node {
60-
Write write;
6160
DataFlow::Node index;
6261
DataFlow::Node rhs;
6362

6463
MapWrite() {
6564
this.getType().hasQualifiedName("net/http", "Header") and
66-
write.writesElement(this, index, rhs)
65+
any(Write write).writesElement(this, index, rhs)
6766
}
6867

6968
override DataFlow::Node getName() { result = index }

go/ql/src/experimental/frameworks/CleverGo.qll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,14 @@ private module CleverGo {
175175
* Models HTTP redirects.
176176
*/
177177
private class HttpRedirect extends Http::Redirect::Range, DataFlow::CallNode {
178-
string package;
179178
DataFlow::Node urlNode;
180179

181180
HttpRedirect() {
182181
// HTTP redirect models for package: clevergo.tech/[email protected]
183-
package = packagePath() and
184182
// Receiver type: Context
185-
(
186-
// signature: func (*Context) Redirect(code int, url string) error
187-
this = any(Method m | m.hasQualifiedName(package, "Context", "Redirect")).getACall() and
188-
urlNode = this.getArgument(1)
189-
)
183+
// signature: func (*Context) Redirect(code int, url string) error
184+
this = any(Method m | m.hasQualifiedName(packagePath(), "Context", "Redirect")).getACall() and
185+
urlNode = this.getArgument(1)
190186
}
191187

192188
override DataFlow::Node getUrl() { result = urlNode }

go/ql/src/experimental/frameworks/Fiber.qll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,14 @@ private module Fiber {
130130
* Models HTTP redirects.
131131
*/
132132
private class Redirect extends Http::Redirect::Range, DataFlow::CallNode {
133-
string package;
134133
DataFlow::Node urlNode;
135134

136135
Redirect() {
137136
// HTTP redirect models for package: github.com/gofiber/[email protected]
138-
package = fiberPackagePath() and
139137
// Receiver type: Ctx
140-
(
141-
// signature: func (*Ctx) Redirect(location string, status ...int)
142-
this = any(Method m | m.hasQualifiedName(package, "Ctx", "Redirect")).getACall() and
143-
urlNode = this.getArgument(0)
144-
)
138+
// signature: func (*Ctx) Redirect(location string, status ...int)
139+
this = any(Method m | m.hasQualifiedName(fiberPackagePath(), "Ctx", "Redirect")).getACall() and
140+
urlNode = this.getArgument(0)
145141
}
146142

147143
override DataFlow::Node getUrl() { result = urlNode }

0 commit comments

Comments
 (0)