Skip to content

Commit 1413615

Browse files
committed
Python: Fix bad join order in TypeTracker::callStep
From a local evaluation against flask DB, after #4649 was merged we would get: ``` Tuple counts for TypeTracker::callStep#ff/2@a21b71: 9876 ~0% {3} r1 = SCAN DataFlowPrivate::DataFlowCall::getArg_dispred#fff AS I OUTPUT I.<2>, I.<0>, I.<1> 9876 ~2% {3} r2 = JOIN r1 WITH project#DataFlowPrivate::DataFlowCall::getArg_dispred#fff AS R ON FIRST 1 OUTPUT r1.<2>, R.<0>, r1.<1> 72388997 ~0% {4} r3 = JOIN r2 WITH DataFlowPublic::ParameterNode::isParameterOf_dispred#fff_201#join_rhs AS R ON FIRST 1 OUTPUT r2.<2>, R.<2>, r2.<1>, R.<1> 4952 ~0% {2} r4 = JOIN r3 WITH DataFlowPrivate::DataFlowCall::getCallable_dispred#ff AS R ON FIRST 2 OUTPUT r3.<2>, r3.<3> return r4 ```
1 parent 09cfb24 commit 1413615

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

python/ql/src/semmle/python/dataflow/new/TypeTracker.qll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,25 @@ private predicate typePreservingStep(Node nodeFrom, Node nodeTo) {
8787
nodeFrom = nodeTo.(PostUpdateNode).getPreUpdateNode()
8888
}
8989

90+
/**
91+
* Helper predicate to avoid bad join order experienced in `callStep`.
92+
*
93+
* This happened when `isParameterOf` was joined _before_ `getCallable`.
94+
*/
95+
pragma[nomagic]
96+
private DataFlowCallable callStepHelper(ArgumentNode nodeFrom, int i) {
97+
exists(DataFlowCall call |
98+
nodeFrom.argumentOf(call, i) and
99+
result = call.getCallable()
100+
)
101+
}
102+
90103
/** Holds if `nodeFrom` steps to `nodeTo` by being passed as a parameter in a call. */
91104
predicate callStep(ArgumentNode nodeFrom, ParameterNode nodeTo) {
92105
// TODO: Support special methods?
93-
exists(DataFlowCall call, int i |
94-
nodeFrom.argumentOf(call, i) and nodeTo.isParameterOf(call.getCallable(), i)
106+
exists(DataFlowCallable callable, int i |
107+
callable = callStepHelper(nodeFrom, i) and
108+
nodeTo.isParameterOf(callable, i)
95109
)
96110
}
97111

0 commit comments

Comments
 (0)