Skip to content

Commit 7392d18

Browse files
committed
Python: use yield step also for taint
Using the comprehension store step meant that all comprehensions would receive taint. This because comprehension flow now goes via a callable, meaning they share the return node.
1 parent fb07a56 commit 7392d18

File tree

2 files changed

+2
-27
lines changed

2 files changed

+2
-27
lines changed

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private predicate synthDictSplatArgumentNodeStoreStep(
168168
)
169169
}
170170

171-
private predicate yieldStoreStep(Node nodeFrom, Content c, Node nodeTo) {
171+
predicate yieldStoreStep(Node nodeFrom, Content c, Node nodeTo) {
172172
exists(Yield yield, Function func |
173173
nodeTo.asCfgNode() = yield.getAFlowNode() and
174174
nodeFrom.asCfgNode() = yield.getValue().getAFlowNode() and
@@ -885,31 +885,6 @@ predicate dictClearStep(Node node, DictionaryElementContent c) {
885885
)
886886
}
887887

888-
/** Data flows from an element expression in a comprehension to the comprehension. */
889-
predicate comprehensionStoreStep(CfgNode nodeFrom, Content c, CfgNode nodeTo) {
890-
// Comprehension
891-
// `[x+1 for x in l]`
892-
// nodeFrom is `x+1`, cfg node
893-
// nodeTo is `[x+1 for x in l]`, cfg node
894-
// c denotes list or set or dictionary without index
895-
//
896-
// List
897-
nodeTo.getNode().getNode().(ListComp).getElt() = nodeFrom.getNode().getNode() and
898-
c instanceof ListElementContent
899-
or
900-
// Set
901-
nodeTo.getNode().getNode().(SetComp).getElt() = nodeFrom.getNode().getNode() and
902-
c instanceof SetElementContent
903-
or
904-
// Dictionary
905-
nodeTo.getNode().getNode().(DictComp).getElt() = nodeFrom.getNode().getNode() and
906-
c instanceof DictionaryElementAnyContent
907-
or
908-
// Generator
909-
nodeTo.getNode().getNode().(GeneratorExp).getElt() = nodeFrom.getNode().getNode() and
910-
c instanceof ListElementContent
911-
}
912-
913888
/**
914889
* Holds if `nodeFrom` flows into the attribute `c` of `nodeTo` via an attribute assignment.
915890
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ predicate containerStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
188188
// TODO: once we have proper flow-summary modeling, we might not need this step any
189189
// longer -- but there needs to be a matching read-step for the store-step, and we
190190
// don't provide that right now.
191-
DataFlowPrivate::comprehensionStoreStep(nodeFrom, _, nodeTo)
191+
DataFlowPrivate::yieldStoreStep(nodeFrom, _, nodeTo)
192192
}
193193

194194
/**

0 commit comments

Comments
 (0)