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

Skip to content

Commit dc38aa8

Browse files
committed
add support for the Method[name] token
1 parent ea01bcf commit dc38aa8

5 files changed

Lines changed: 10 additions & 8 deletions

File tree

python/ql/lib/semmle/python/frameworks/data/internal/ApiGraphModelsSpecific.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ API::Node getExtraSuccessorFromNode(API::Node node, AccessPathToken token) {
6060
or
6161
token.getName() = "Subclass" and
6262
result = node.getASubclass*()
63+
or
64+
token.getName() = "Method" and
65+
result = node.getMember(token.getAnArgument()).getReturn()
6366
// Some features don't have MaD tokens yet, they would need to be added to API-graphs first.
6467
// - decorators ("DecoratedClass", "DecoratedMember", "DecoratedParameter")
6568
// - Array/Map elements ("ArrayElement", "Element", "MapKey", "MapValue")
@@ -164,7 +167,7 @@ predicate isExtraValidNoArgumentTokenInIdentifyingAccessPath(string name) {
164167
*/
165168
bindingset[name, argument]
166169
predicate isExtraValidTokenArgumentInIdentifyingAccessPath(string name, string argument) {
167-
name = ["Member"] and
170+
name = ["Member", "Method"] and
168171
exists(argument)
169172
or
170173
name = ["Argument", "Parameter"] and

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ isSource
4242
| test.py:41:8:41:27 | ControlFlowNode for Attribute() | test-source |
4343
| test.py:46:7:46:16 | ControlFlowNode for SubClass() | test-source |
4444
| test.py:51:8:51:18 | ControlFlowNode for Sub2Class() | test-source |
45+
| test.py:53:7:53:16 | ControlFlowNode for Attribute() | test-source |
4546
syntaxErrors
4647
| Member[foo |
4748
| Member[foo] .Member[bar] |

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ class SubClass (CommonTokens.Super):
4848
class Sub2Class (CommonTokens.Class):
4949
pass
5050

51-
sub2 = Sub2Class()
51+
sub2 = Sub2Class()
52+
53+
val = inst.foo()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Sinks extends ModelInput::SinkModelCsv {
5757
// TODO: Non-positional arguments (including Named parameters)
5858
// TODO: Any argument
5959
// TODO: Test taint steps.
60-
// TODO: Should `instance()` be shorthand for `subClass*().getReturn()`?
6160
// TODO: // There are no API-graph edges for: ArrayElement, Element, MapKey, MapValue (remove from valid tokens list)
6261
class Sources extends ModelInput::SourceModelCsv {
6362
// package;type;path;kind
@@ -74,6 +73,8 @@ class Sources extends ModelInput::SourceModelCsv {
7473
"testlib;;Member[CommonTokens].Member[makePromise].ReturnValue.Awaited;test-source", //
7574
"testlib;;Member[CommonTokens].Member[Class].Instance;test-source", //
7675
"testlib;;Member[CommonTokens].Member[Super].Subclass.Instance;test-source", //
76+
// method
77+
"testlib;;Member[CommonTokens].Member[Class].Instance.Method[foo];test-source", //
7778
]
7879
}
7980
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
| CSV type row should have 5 columns but has 8: test;TooManyColumns;;;Member[Foo].Instance;too;many;columns |
33
| Invalid argument '0-1' in token 'Argument[0-1]' in access path: Method[foo].Argument[0-1] |
44
| Invalid argument '*' in token 'Argument[*]' in access path: Method[foo].Argument[*] |
5-
| Invalid argument 'foo' in token 'Method[foo]' in access path: Method[foo].Arg[0] |
6-
| Invalid argument 'foo' in token 'Method[foo]' in access path: Method[foo].Argument |
7-
| Invalid argument 'foo' in token 'Method[foo]' in access path: Method[foo].Argument[0-1] |
8-
| Invalid argument 'foo' in token 'Method[foo]' in access path: Method[foo].Argument[*] |
9-
| Invalid argument 'foo' in token 'Method[foo]' in access path: Method[foo].Member |
105
| Invalid token 'Argument' is missing its arguments, in access path: Method[foo].Argument |
116
| Invalid token 'Member' is missing its arguments, in access path: Method[foo].Member |
127
| Invalid token name 'Arg' in access path: Method[foo].Arg[0] |

0 commit comments

Comments
 (0)