Skip to content

Commit 283173a

Browse files
committed
Address review comments
1 parent 4908721 commit 283173a

File tree

13 files changed

+87
-72
lines changed

13 files changed

+87
-72
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,11 @@ private module Cached {
391391

392392
/**
393393
* Holds if `p` is the parameter of a viable dispatch target of `call`,
394-
* and `p` matches arguments at position `apos`.
394+
* and `p` has position `ppos`.
395395
*/
396396
pragma[nomagic]
397-
private predicate viableParam(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
398-
exists(ParameterPosition ppos |
399-
p.isParameterOf(viableCallableExt(call), ppos) and
400-
parameterMatch(ppos, apos)
401-
)
397+
private predicate viableParam(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
398+
p.isParameterOf(viableCallableExt(call), ppos)
402399
}
403400

404401
/**
@@ -407,9 +404,9 @@ private module Cached {
407404
*/
408405
cached
409406
predicate viableParamArg(DataFlowCall call, ParamNode p, ArgNode arg) {
410-
exists(ArgumentPosition pos |
411-
viableParam(call, pos, p) and
412-
arg.argumentOf(call, pos) and
407+
exists(ParameterPosition ppos |
408+
viableParam(call, ppos, p) and
409+
argumentPositionMatch(call, arg, ppos) and
413410
compatibleTypes(getNodeDataFlowType(arg), getNodeDataFlowType(p))
414411
)
415412
}

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,11 @@ private module Cached {
391391

392392
/**
393393
* Holds if `p` is the parameter of a viable dispatch target of `call`,
394-
* and `p` matches arguments at position `apos`.
394+
* and `p` has position `ppos`.
395395
*/
396396
pragma[nomagic]
397-
private predicate viableParam(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
398-
exists(ParameterPosition ppos |
399-
p.isParameterOf(viableCallableExt(call), ppos) and
400-
parameterMatch(ppos, apos)
401-
)
397+
private predicate viableParam(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
398+
p.isParameterOf(viableCallableExt(call), ppos)
402399
}
403400

404401
/**
@@ -407,9 +404,9 @@ private module Cached {
407404
*/
408405
cached
409406
predicate viableParamArg(DataFlowCall call, ParamNode p, ArgNode arg) {
410-
exists(ArgumentPosition pos |
411-
viableParam(call, pos, p) and
412-
arg.argumentOf(call, pos) and
407+
exists(ParameterPosition ppos |
408+
viableParam(call, ppos, p) and
409+
argumentPositionMatch(call, arg, ppos) and
413410
compatibleTypes(getNodeDataFlowType(arg), getNodeDataFlowType(p))
414411
)
415412
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,11 @@ private module Cached {
391391

392392
/**
393393
* Holds if `p` is the parameter of a viable dispatch target of `call`,
394-
* and `p` matches arguments at position `apos`.
394+
* and `p` has position `ppos`.
395395
*/
396396
pragma[nomagic]
397-
private predicate viableParam(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
398-
exists(ParameterPosition ppos |
399-
p.isParameterOf(viableCallableExt(call), ppos) and
400-
parameterMatch(ppos, apos)
401-
)
397+
private predicate viableParam(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
398+
p.isParameterOf(viableCallableExt(call), ppos)
402399
}
403400

404401
/**
@@ -407,9 +404,9 @@ private module Cached {
407404
*/
408405
cached
409406
predicate viableParamArg(DataFlowCall call, ParamNode p, ArgNode arg) {
410-
exists(ArgumentPosition pos |
411-
viableParam(call, pos, p) and
412-
arg.argumentOf(call, pos) and
407+
exists(ParameterPosition ppos |
408+
viableParam(call, ppos, p) and
409+
argumentPositionMatch(call, arg, ppos) and
413410
compatibleTypes(getNodeDataFlowType(arg), getNodeDataFlowType(p))
414411
)
415412
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ module Public {
144144
noComponentSpecificCsv(sc) and
145145
(
146146
exists(ArgumentPosition pos |
147-
sc = TParameterSummaryComponent(pos) and result = "Parameter[" + pos + "]"
147+
sc = TParameterSummaryComponent(pos) and
148+
result = "Parameter[" + getArgumentPositionCsv(pos) + "]"
148149
)
149150
or
150151
exists(ParameterPosition pos |
151-
sc = TArgumentSummaryComponent(pos) and result = "Argument[" + pos + "]"
152+
sc = TArgumentSummaryComponent(pos) and
153+
result = "Argument[" + getParameterPositionCsv(pos) + "]"
152154
)
153155
or
154156
sc = TReturnSummaryComponent(getReturnValueKind()) and result = "ReturnValue"

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ string getComponentSpecificCsv(SummaryComponent sc) {
156156
)
157157
}
158158

159+
/** Gets the textual representation of a parameter position in the format used for flow summaries. */
160+
string getParameterPositionCsv(ParameterPosition pos) { result = pos.toString() }
161+
162+
/** Gets the textual representation of an argument position in the format used for flow summaries. */
163+
string getArgumentPositionCsv(ArgumentPosition pos) { result = pos.toString() }
164+
159165
class SourceOrSinkElement = Element;
160166

161167
/** Gets the return kind corresponding to specification `"ReturnValue"`. */
@@ -222,18 +228,21 @@ predicate interpretInputSpecific(string c, InterpretNode mid, InterpretNode n) {
222228
)
223229
}
224230

225-
/** Gets the argument position obtained by parsing `X` in `Parameter[X]`. */
226231
bindingset[s]
227-
ArgumentPosition parseParamBody(string s) {
228-
result.getPosition() = s.regexpCapture("([-0-9]+)", 1).toInt()
232+
private int parsePosition(string s) {
233+
result = s.regexpCapture("([-0-9]+)", 1).toInt()
229234
or
230235
exists(int n1, int n2 |
231236
s.regexpCapture("([-0-9]+)\\.\\.([0-9]+)", 1).toInt() = n1 and
232237
s.regexpCapture("([-0-9]+)\\.\\.([0-9]+)", 2).toInt() = n2 and
233-
result.getPosition() in [n1 .. n2]
238+
result in [n1 .. n2]
234239
)
235240
}
236241

242+
/** Gets the argument position obtained by parsing `X` in `Parameter[X]`. */
243+
bindingset[s]
244+
ArgumentPosition parseParamBody(string s) { result.getPosition() = parsePosition(s) }
245+
237246
/** Gets the parameter position obtained by parsing `X` in `Argument[X]`. */
238247
bindingset[s]
239-
ParameterPosition parseArgBody(string s) { result.getPosition() = parseParamBody(s).getPosition() }
248+
ParameterPosition parseArgBody(string s) { result.getPosition() = parsePosition(s) }

docs/ql-libraries/dataflow/dataflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ language-defined classes `ParameterPosition` and `ArgumentPosition`,
165165
so these three predicates must be defined:
166166
```ql
167167
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
168-
predicate isParameterNode(ParameterNodeImpl p, DataFlowCallable c, ParameterPosition pos)
168+
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos)
169169
170170
/** Holds if `arg` is an `ArgumentNode` of `c` with position `pos`. */
171171
predicate isArgumentNode(ArgumentNode arg, DataFlowCall c, ArgumentPosition pos)

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,11 @@ private module Cached {
391391

392392
/**
393393
* Holds if `p` is the parameter of a viable dispatch target of `call`,
394-
* and `p` matches arguments at position `apos`.
394+
* and `p` has position `ppos`.
395395
*/
396396
pragma[nomagic]
397-
private predicate viableParam(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
398-
exists(ParameterPosition ppos |
399-
p.isParameterOf(viableCallableExt(call), ppos) and
400-
parameterMatch(ppos, apos)
401-
)
397+
private predicate viableParam(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
398+
p.isParameterOf(viableCallableExt(call), ppos)
402399
}
403400

404401
/**
@@ -407,9 +404,9 @@ private module Cached {
407404
*/
408405
cached
409406
predicate viableParamArg(DataFlowCall call, ParamNode p, ArgNode arg) {
410-
exists(ArgumentPosition pos |
411-
viableParam(call, pos, p) and
412-
arg.argumentOf(call, pos) and
407+
exists(ParameterPosition ppos |
408+
viableParam(call, ppos, p) and
409+
argumentPositionMatch(call, arg, ppos) and
413410
compatibleTypes(getNodeDataFlowType(arg), getNodeDataFlowType(p))
414411
)
415412
}

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ module Public {
144144
noComponentSpecificCsv(sc) and
145145
(
146146
exists(ArgumentPosition pos |
147-
sc = TParameterSummaryComponent(pos) and result = "Parameter[" + pos + "]"
147+
sc = TParameterSummaryComponent(pos) and
148+
result = "Parameter[" + getArgumentPositionCsv(pos) + "]"
148149
)
149150
or
150151
exists(ParameterPosition pos |
151-
sc = TArgumentSummaryComponent(pos) and result = "Argument[" + pos + "]"
152+
sc = TArgumentSummaryComponent(pos) and
153+
result = "Argument[" + getParameterPositionCsv(pos) + "]"
152154
)
153155
or
154156
sc = TReturnSummaryComponent(getReturnValueKind()) and result = "ReturnValue"

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ string getComponentSpecificCsv(SummaryComponent sc) {
9696
exists(Content c | sc = TContentSummaryComponent(c) and result = getContentSpecificCsv(c))
9797
}
9898

99+
/** Gets the textual representation of a parameter position in the format used for flow summaries. */
100+
string getParameterPositionCsv(ParameterPosition pos) { result = pos.toString() }
101+
102+
/** Gets the textual representation of an argument position in the format used for flow summaries. */
103+
string getArgumentPositionCsv(ArgumentPosition pos) { result = pos.toString() }
104+
99105
class SourceOrSinkElement = Top;
100106

101107
/**
@@ -188,9 +194,8 @@ predicate interpretInputSpecific(string c, InterpretNode mid, InterpretNode n) {
188194
)
189195
}
190196

191-
/** Gets the argument position obtained by parsing `X` in `Parameter[X]`. */
192197
bindingset[s]
193-
ArgumentPosition parseParamBody(string s) {
198+
private int parsePosition(string s) {
194199
result = s.regexpCapture("([-0-9]+)", 1).toInt()
195200
or
196201
exists(int n1, int n2 |
@@ -200,6 +205,10 @@ ArgumentPosition parseParamBody(string s) {
200205
)
201206
}
202207

208+
/** Gets the argument position obtained by parsing `X` in `Parameter[X]`. */
209+
bindingset[s]
210+
ArgumentPosition parseParamBody(string s) { result = parsePosition(s) }
211+
203212
/** Gets the parameter position obtained by parsing `X` in `Argument[X]`. */
204213
bindingset[s]
205-
ParameterPosition parseArgBody(string s) { result = parseParamBody(s) }
214+
ParameterPosition parseArgBody(string s) { result = parsePosition(s) }

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImplCommon.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,11 @@ private module Cached {
391391

392392
/**
393393
* Holds if `p` is the parameter of a viable dispatch target of `call`,
394-
* and `p` matches arguments at position `apos`.
394+
* and `p` has position `ppos`.
395395
*/
396396
pragma[nomagic]
397-
private predicate viableParam(DataFlowCall call, ArgumentPosition apos, ParamNode p) {
398-
exists(ParameterPosition ppos |
399-
p.isParameterOf(viableCallableExt(call), ppos) and
400-
parameterMatch(ppos, apos)
401-
)
397+
private predicate viableParam(DataFlowCall call, ParameterPosition ppos, ParamNode p) {
398+
p.isParameterOf(viableCallableExt(call), ppos)
402399
}
403400

404401
/**
@@ -407,9 +404,9 @@ private module Cached {
407404
*/
408405
cached
409406
predicate viableParamArg(DataFlowCall call, ParamNode p, ArgNode arg) {
410-
exists(ArgumentPosition pos |
411-
viableParam(call, pos, p) and
412-
arg.argumentOf(call, pos) and
407+
exists(ParameterPosition ppos |
408+
viableParam(call, ppos, p) and
409+
argumentPositionMatch(call, arg, ppos) and
413410
compatibleTypes(getNodeDataFlowType(arg), getNodeDataFlowType(p))
414411
)
415412
}

0 commit comments

Comments
 (0)