Skip to content

Commit 2409a78

Browse files
committed
Python: Remove func tag in some situations.
Also make ArgumentNode public
1 parent 3fc085f commit 2409a78

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,6 @@ class SpecialCall extends DataFlowCall, TSpecialCall {
703703
}
704704
}
705705

706-
/** A data flow node that represents a call argument. */
707-
class ArgumentNode extends Node {
708-
ArgumentNode() { this = any(DataFlowCall c).getArg(_) }
709-
710-
/** Holds if this argument occurs at the given position in the given call. */
711-
predicate argumentOf(DataFlowCall call, int pos) { this = call.getArg(pos) }
712-
713-
/** Gets the call in which this node is an argument. */
714-
final DataFlowCall getCall() { this.argumentOf(result, _) }
715-
}
716-
717706
/** Gets a viable run-time target for the call `call`. */
718707
DataFlowCallable viableCallable(DataFlowCall call) { result = call.getCallable() }
719708

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ class ParameterNode extends CfgNode {
193193
Parameter getParameter() { result = def.getParameter() }
194194
}
195195

196+
/** A data flow node that represents a call argument. */
197+
class ArgumentNode extends Node {
198+
ArgumentNode() { this = any(DataFlowCall c).getArg(_) }
199+
200+
/** Holds if this argument occurs at the given position in the given call. */
201+
predicate argumentOf(DataFlowCall call, int pos) { this = call.getArg(pos) }
202+
203+
/** Gets the call in which this node is an argument. */
204+
final DataFlowCall getCall() { this.argumentOf(result, _) }
205+
}
206+
196207
/**
197208
* A node associated with an object after an operation that might have
198209
* changed its state.

python/ql/test/experimental/dataflow/TestUtil/RoutingTest.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,19 @@ abstract class RoutingTest extends InlineExpectationsTest {
2828
value = "\"" + prettyNode(fromNode).replaceAll("\"", "'") + "\""
2929
or
3030
tag = "func" and
31-
value = toNode.getEnclosingCallable().getCallableValue().getScope().getQualifiedName() // TODO: More robust pretty printing?
31+
not fromFunc(fromNode) = toFunc(toNode) and
32+
value = toFunc(toNode)
3233
)
3334
)
3435
}
36+
37+
pragma[inline]
38+
private string fromFunc(DataFlow::ArgumentNode fromNode) {
39+
result = fromNode.getCall().getNode().(CallNode).getFunction().getNode().(Name).getId()
40+
}
41+
42+
pragma[inline]
43+
private string toFunc(DataFlow::Node toNode) {
44+
result = toNode.getEnclosingCallable().getCallableValue().getScope().getQualifiedName() // TODO: More robust pretty printing?
45+
}
3546
}

python/ql/test/experimental/dataflow/coverage/argumentPassing.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_argument_passing1():
9191

9292
@expects(7)
9393
def test_argument_passing2():
94-
argument_passing(arg1, arg2, arg3, f=arg6) #$ arg1="arg1" arg2="arg2" arg3="arg3" func=argument_passing
94+
argument_passing(arg1, arg2, arg3, f=arg6) #$ arg1="arg1" arg2="arg2" arg3="arg3"
9595

9696

9797
def with_pos_only(a, /, b):
@@ -101,9 +101,9 @@ def with_pos_only(a, /, b):
101101

102102
@expects(6)
103103
def test_pos_only():
104-
with_pos_only(arg1, arg2) #$ arg1="arg1" arg2="arg2" func=with_pos_only
105-
with_pos_only(arg1, b=arg2) #$ arg1="arg1" arg2="arg2" func=with_pos_only
106-
with_pos_only(arg1, *(arg2,)) #$ arg1="arg1" func=with_pos_only MISSING: arg2="arg2"
104+
with_pos_only(arg1, arg2) #$ arg1="arg1" arg2="arg2"
105+
with_pos_only(arg1, b=arg2) #$ arg1="arg1" arg2="arg2"
106+
with_pos_only(arg1, *(arg2,)) #$ arg1="arg1" MISSING: arg2="arg2"
107107

108108

109109
def with_multiple_kw_args(a, b, c):
@@ -114,8 +114,8 @@ def with_multiple_kw_args(a, b, c):
114114

115115
@expects(12)
116116
def test_multiple_kw_args():
117-
with_multiple_kw_args(b=arg2, c=arg3, a=arg1) #$ arg1="arg1" arg2="arg2" arg3="arg3" func=with_multiple_kw_args
118-
with_multiple_kw_args(arg1, *(arg2,), arg3) #$ arg1="arg1" func=with_multiple_kw_args MISSING: arg2="arg2" arg3="arg3"
117+
with_multiple_kw_args(b=arg2, c=arg3, a=arg1) #$ arg1="arg1" arg2="arg2" arg3="arg3"
118+
with_multiple_kw_args(arg1, *(arg2,), arg3) #$ arg1="arg1" MISSING: arg2="arg2" arg3="arg3"
119119
with_multiple_kw_args(arg1, **{"c": arg3}, b=arg2) #$ arg1="arg1" arg3="arg3" func=with_multiple_kw_args MISSING: arg2="arg2"
120120
with_multiple_kw_args(**{"b": arg2}, **{"c": arg3}, **{"a": arg1}) #$ arg1="arg1" arg2="arg2" arg3="arg3" func=with_multiple_kw_args
121121

@@ -129,8 +129,8 @@ def with_default_arguments(a=arg1, b=arg2, c=arg3): # Need a mechanism to test
129129
@expects(12)
130130
def test_default_arguments():
131131
with_default_arguments()
132-
with_default_arguments(arg1) #$ arg1="arg1" func=with_default_arguments
133-
with_default_arguments(b=arg2) #$ arg2="arg2" func=with_default_arguments
132+
with_default_arguments(arg1) #$ arg1="arg1"
133+
with_default_arguments(b=arg2) #$ arg2="arg2"
134134
with_default_arguments(**{"c": arg3}) #$ arg3="arg3" func=with_default_arguments
135135

136136

@@ -157,7 +157,7 @@ def grab_baz(baz):
157157

158158
@expects(4)
159159
def test_grab():
160-
grab_foo_bar_baz(baz=arg3, bar=arg2, foo=arg1) #$ arg1="arg1" arg2="arg2" arg3="arg3" func=grab_foo_bar_baz func=grab_bar_baz func=grab_baz
160+
grab_foo_bar_baz(baz=arg3, bar=arg2, foo=arg1) #$ arg1="arg1" arg2="arg2" arg3="arg3" func=grab_bar_baz func=grab_baz
161161

162162

163163
# All combinations

python/ql/test/experimental/dataflow/coverage/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,4 @@ def return_from_inner_scope(x):
590590
return SOURCE
591591

592592
def test_return_from_inner_scope():
593-
SINK(return_from_inner_scope([]))
593+
SINK(return_from_inner_scope([])) #$ flow="SOURCE, l:-3 -> return_from_inner_scope(..)"

0 commit comments

Comments
 (0)