Skip to content

Commit 580e68d

Browse files
committed
python: add support for lower bound position
1 parent 45bb4a0 commit 580e68d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ newtype TParameterPosition =
5757
// parameter positions available.
5858
FlowSummaryImpl::ParsePositions::isParsedPositionalArgumentPosition(_, index)
5959
} or
60+
TPositionalParameterLowerBoundPosition(int pos) {
61+
FlowSummaryImpl::ParsePositions::isParsedArgumentLowerBoundPosition(_, pos)
62+
} or
6063
TKeywordParameterPosition(string name) {
6164
name = any(Parameter p).getName()
6265
or
@@ -91,6 +94,9 @@ class ParameterPosition extends TParameterPosition {
9194
/** Holds if this position represents a positional parameter at (0-based) `index`. */
9295
predicate isPositional(int index) { this = TPositionalParameterPosition(index) }
9396

97+
/** Holds if this position represents any positional parameter starting from position `pos`. */
98+
predicate isPositionalLowerBound(int pos) { this = TPositionalParameterLowerBoundPosition(pos) }
99+
94100
/** Holds if this position represents a keyword parameter named `name`. */
95101
predicate isKeyword(string name) { this = TKeywordParameterPosition(name) }
96102

@@ -123,6 +129,8 @@ class ParameterPosition extends TParameterPosition {
123129
or
124130
exists(int index | this.isPositional(index) and result = "position " + index)
125131
or
132+
exists(int pos | this.isPositionalLowerBound(pos) and result = "position " + pos + "..")
133+
or
126134
exists(string name | this.isKeyword(name) and result = "keyword " + name)
127135
or
128136
exists(int index | this.isStarArgs(index) and result = "*args at " + index)
@@ -211,6 +219,10 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
211219
or
212220
exists(int index | ppos.isPositional(index) and apos.isPositional(index))
213221
or
222+
exists(int index1, int index2 |
223+
ppos.isPositionalLowerBound(index1) and apos.isPositional(index2) and index2 >= index1
224+
)
225+
or
214226
exists(string name | ppos.isKeyword(name) and apos.isKeyword(name))
215227
or
216228
exists(int index | ppos.isStarArgs(index) and apos.isStarArgs(index))
@@ -360,6 +372,10 @@ abstract class DataFlowFunction extends DataFlowCallable, TFunction {
360372
result.getParameter() = func.getArg(index + this.positionalOffset())
361373
)
362374
or
375+
exists(int index1, int index2 | ppos.isPositionalLowerBound(index1) and index2 >= index1 |
376+
result.getParameter() = func.getArg(index2 + this.positionalOffset())
377+
)
378+
or
363379
exists(string name | ppos.isKeyword(name) | result.getParameter() = func.getArgByName(name))
364380
or
365381
// `*args`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ module ParsePositions {
195195
i = AccessPath::parseInt(c)
196196
}
197197

198+
predicate isParsedArgumentLowerBoundPosition(string c, int i) {
199+
isArgBody(c) and
200+
i = AccessPath::parseLowerBound(c)
201+
}
202+
198203
predicate isParsedKeywordArgumentPosition(string c, string argName) {
199204
isArgBody(c) and
200205
c = argName + ":"

0 commit comments

Comments
 (0)