Skip to content

Commit ced000a

Browse files
committed
Add Argument.getACorrespondingSyntacticArgument
1 parent 652dd88 commit ced000a

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

go/ql/lib/semmle/go/Concepts.qll

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ private class DefaultFileSystemAccess extends FileSystemAccess::Range, DataFlow:
121121
}
122122

123123
override DataFlow::Node getAPathArgument() {
124-
not pathArgument instanceof DataFlow::ImplicitVarargsSlice and
125-
result = pathArgument
126-
or
127-
pathArgument instanceof DataFlow::ImplicitVarargsSlice and
128-
result = this.getAnImplicitVarargsArgument()
124+
result = pathArgument.getACorrespondingSyntacticArgument()
129125
}
130126
}
131127

@@ -378,19 +374,15 @@ module LoggerCall {
378374
}
379375

380376
private class DefaultLoggerCall extends LoggerCall::Range, DataFlow::CallNode {
381-
DataFlow::ArgumentNode messageComponent;
377+
DataFlow::ArgumentNode messageArgument;
382378

383379
DefaultLoggerCall() {
384-
sinkNode(messageComponent, "log-injection") and
385-
this = messageComponent.getCall()
380+
sinkNode(messageArgument, "log-injection") and
381+
this = messageArgument.getCall()
386382
}
387383

388384
override DataFlow::Node getAMessageComponent() {
389-
not messageComponent instanceof DataFlow::ImplicitVarargsSlice and
390-
result = messageComponent
391-
or
392-
messageComponent instanceof DataFlow::ImplicitVarargsSlice and
393-
result = this.getAnImplicitVarargsArgument()
385+
result = messageArgument.getACorrespondingSyntacticArgument()
394386
}
395387
}
396388

go/ql/lib/semmle/go/concepts/HTTP.qll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,7 @@ module Http {
332332
)
333333
}
334334

335-
override DataFlow::Node getUrl() {
336-
not url instanceof DataFlow::ImplicitVarargsSlice and
337-
result = url
338-
or
339-
url instanceof DataFlow::ImplicitVarargsSlice and
340-
result = this.getAnImplicitVarargsArgument()
341-
}
335+
override DataFlow::Node getUrl() { result = url.getACorrespondingSyntacticArgument() }
342336

343337
override Http::ResponseWriter getResponseWriter() {
344338
rw = -1 and result.getANode() = this.getReceiver()

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,7 @@ module Public {
841841
or
842842
preupd = getAWrittenNode()
843843
or
844-
(
845-
preupd instanceof ArgumentNode and not preupd instanceof ImplicitVarargsSlice
846-
or
847-
preupd = any(CallNode c).getAnImplicitVarargsArgument()
848-
) and
844+
preupd = any(ArgumentNode arg).getACorrespondingSyntacticArgument() and
849845
mutableType(preupd.getType())
850846
) and
851847
(
@@ -889,6 +885,21 @@ module Public {
889885
* Gets this argument's position.
890886
*/
891887
int getPosition() { result = i }
888+
889+
/**
890+
* Gets a data-flow node for a syntactic argument corresponding this this
891+
* argument. If this argument is not an implicit varargs slice then this
892+
* will just be the argument itself. If this argument is an implicit
893+
* varargs slice then this will be a data-flow node that for an argument
894+
* that is stored in the implicit varargs slice.
895+
*/
896+
Node getACorrespondingSyntacticArgument() {
897+
not this instanceof DataFlow::ImplicitVarargsSlice and
898+
result = this
899+
or
900+
this instanceof DataFlow::ImplicitVarargsSlice and
901+
result = c.getAnImplicitVarargsArgument()
902+
}
892903
}
893904

894905
/**

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ module SQL {
7070
private class DefaultQueryString extends Range {
7171
DefaultQueryString() {
7272
exists(DataFlow::ArgumentNode arg | sinkNode(arg, "sql-injection") |
73-
not arg instanceof DataFlow::ImplicitVarargsSlice and
74-
this = arg
75-
or
76-
arg instanceof DataFlow::ImplicitVarargsSlice and
77-
this = arg.getCall().getAnImplicitVarargsArgument()
73+
this = arg.getACorrespondingSyntacticArgument()
7874
)
7975
}
8076
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ private class DefaultSystemCommandExecution extends SystemCommandExecution::Rang
1616
}
1717

1818
override DataFlow::Node getCommandName() {
19-
not commandName instanceof DataFlow::ImplicitVarargsSlice and
20-
result = commandName
21-
or
22-
commandName instanceof DataFlow::ImplicitVarargsSlice and
23-
result = this.getAnImplicitVarargsArgument()
19+
result = commandName.getACorrespondingSyntacticArgument()
2420
}
2521
}
2622

0 commit comments

Comments
 (0)