Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ffc05c

Browse files
committed
count both named and positional arguments in the WithArity filter
1 parent c0eca0d commit 8ffc05c

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

python/ql/lib/semmle/python/ApiGraphs.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ module API {
349349
result.getAnImmediateUse() = this
350350
}
351351

352-
/** Gets the number of arguments of this call. */
353-
int getNumArgument() { result = count(this.getArg(_)) }
352+
/** Gets the number of arguments of this call. Both positional and named arguments are counted. */
353+
int getNumArgument() { result = count([this.getArg(_), this.getArgByName(_)]) }
354354
}
355355

356356
/**

python/ql/test/library-tests/frameworks/data/test.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ isSink
4646
| test.py:85:8:85:53 | ControlFlowNode for Attribute() | test-sink |
4747
| test.py:86:8:86:60 | ControlFlowNode for Attribute() | test-sink |
4848
| test.py:87:8:87:67 | ControlFlowNode for Attribute() | test-sink |
49+
| test.py:89:21:89:23 | ControlFlowNode for one | test-source |
50+
| test.py:90:25:90:27 | ControlFlowNode for one | test-source |
4951
isSource
5052
| test.py:3:5:3:15 | ControlFlowNode for getSource() | test-source |
5153
| test.py:9:8:9:14 | ControlFlowNode for alias() | test-source |

python/ql/test/library-tests/frameworks/data/test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,9 @@ def secondAndAfter(self, arg1, arg2, arg3, arg4, arg5):
8484

8585
mySink(Steps.preserveAllButFirstArgument(getSource())) # NO FLOW
8686
mySink(Steps.preserveAllButFirstArgument("foo", getSource())) # FLOW
87-
mySink(Steps.preserveAllButFirstArgument("foo", "bar", getSource())) # FLOW
87+
mySink(Steps.preserveAllButFirstArgument("foo", "bar", getSource())) # FLOW
88+
89+
CallFilter.arityOne(one) # match
90+
CallFilter.arityOne(one=one) # match
91+
CallFilter.arityOne(one, two=two) # NO match
92+
CallFilter.arityOne(one=one, two=two) # NO match

python/ql/test/library-tests/frameworks/data/test.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Sinks extends ModelInput::SinkModelCsv {
4141
"testlib;;Member[Args].Member[lastarg].Argument[N-1];test-source", //
4242
"testlib;;Member[Args].Member[nonFist].Argument[1..];test-source", //
4343
// callsite filter.
44-
"testlib;;Member[CallFilter].Member[arityOne].WithArity[1].Argument[0..];test-source", //
44+
"testlib;;Member[CallFilter].Member[arityOne].WithArity[1].Argument[any];test-source", //
4545
"testlib;;Member[CallFilter].Member[twoOrMore].WithArity[2..].Argument[0..];test-source", //
4646
// testing non-positional arguments
4747
"testlib;;Member[ArgPos].Member[selfThing].Argument[self];test-source", //

0 commit comments

Comments
 (0)