Skip to content

Commit 38b1eb7

Browse files
committed
Python: just use ListElementContent for iterables
1 parent f39dc41 commit 38b1eb7

File tree

3 files changed

+8
-27
lines changed

3 files changed

+8
-27
lines changed

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -179,33 +179,10 @@ private predicate synthDictSplatArgumentNodeStoreStep(
179179
* data from `x.name` is stored into the `yield` (and can subsequently be read out of the iterable).
180180
*/
181181
predicate yieldStoreStep(Node nodeFrom, Content c, Node nodeTo) {
182-
exists(Yield yield, Function func |
182+
exists(Yield yield |
183183
nodeTo.asCfgNode() = yield.getAFlowNode() and
184184
nodeFrom.asCfgNode() = yield.getValue().getAFlowNode() and
185-
func.containsInScope(yield)
186-
|
187-
exists(Comp comp | func = comp.getFunction() |
188-
(
189-
comp instanceof ListComp or
190-
comp instanceof GeneratorExp
191-
) and
192-
c instanceof ListElementContent
193-
or
194-
comp instanceof SetComp and
195-
c instanceof SetElementContent
196-
or
197-
comp instanceof DictComp and
198-
c instanceof DictionaryElementAnyContent
199-
)
200-
or
201-
not exists(Comp comp | func = comp.getFunction()) and
202-
(
203-
c instanceof ListElementContent
204-
or
205-
c instanceof SetElementContent
206-
or
207-
c instanceof DictionaryElementAnyContent
208-
)
185+
c instanceof ListElementContent
209186
)
210187
}
211188

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,6 +4224,10 @@ module StdlibPrivate {
42244224
preservesValue = true
42254225
)
42264226
or
4227+
input = "Argument[0].ListElement.TupleElement[1]" and
4228+
output = "ReturnValue.DictionaryElementAny" and
4229+
preservesValue = true
4230+
or
42274231
exists(DataFlow::DictionaryElementContent dc, string key | key = dc.getKey() |
42284232
input = "Argument[" + key + ":]" and
42294233
output = "ReturnValue.DictionaryElement[" + key + "]" and

python/ql/test/library-tests/dataflow/coverage/test_builtins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def test_dict_from_keyword():
132132
@expects(2)
133133
def test_dict_from_list():
134134
d = dict([("k", SOURCE), ("k1", NONSOURCE)])
135-
SINK(d["k"]) #$ MISSING: flow="SOURCE, l:-1 -> d[k]"
136-
SINK_F(d["k1"])
135+
SINK(d["k"]) #$ flow="SOURCE, l:-1 -> d['k']"
136+
SINK_F(d["k1"]) #$ SPURIOUS: flow="SOURCE, l:-2 -> d['k1']" // due to imprecise list content
137137

138138
@expects(2)
139139
def test_dict_from_dict():

0 commit comments

Comments
 (0)