Skip to content

Commit 4e36008

Browse files
Add tests
1 parent 642f9dc commit 4e36008

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4576,7 +4576,7 @@ module StdlibPrivate {
45764576
)
45774577
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
45784578
) and
4579-
output = "Argument[0].Parameter[0]" and
4579+
(output = "Argument[0].Parameter[0]" or output = "ReturnValue.ListElement") and
45804580
preservesValue = true
45814581
}
45824582
}

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

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,111 @@ def test_next_dict():
366366
i = iter(d)
367367
n = next(i)
368368
SINK(n) #$ MISSING: flow="SOURCE, l:-3 -> n"
369+
370+
### map
371+
372+
@expects(4)
373+
def test_map_list():
374+
l1 = [SOURCE]
375+
l2 = [NONSOURCE]
376+
377+
def f(p1,p2):
378+
SINK(p1) #$ flow="SOURCE, l:-4 -> p1"
379+
SINK_F(p2)
380+
381+
return p1,p2
382+
383+
rl = list(map(f, l1, l2))
384+
SINK(rl[0][0]) #$ flow="SOURCE, l:-10 -> rl[0][0]"
385+
SINK_F(rl[0][1])
386+
387+
@expects(4)
388+
def test_map_set():
389+
s1 = {SOURCE}
390+
s2 = {NONSOURCE}
391+
392+
def f(p1,p2):
393+
SINK(p1) #$ flow="SOURCE, l:-4 -> p1"
394+
SINK_F(p2)
395+
396+
return p1,p2
397+
398+
rl = list(map(f, s1, s2))
399+
SINK(rl[0][0]) #$ flow="SOURCE, l:-10 -> rl[0][0]"
400+
SINK_F(rl[0][1])
401+
402+
@expects(4)
403+
def test_map_tuple():
404+
t1 = (SOURCE,)
405+
t2 = (NONSOURCE,)
406+
407+
def f(p1,p2):
408+
SINK(p1) #$ flow="SOURCE, l:-4 -> p1"
409+
SINK_F(p2)
410+
411+
return p1,p2
412+
413+
rl = list(map(f, t1, t2))
414+
SINK(rl[0][0]) #$ flow="SOURCE, l:-10 -> rl[0][0]"
415+
SINK_F(rl[0][1])
416+
417+
@expects(4)
418+
def test_map_dict():
419+
d1 = {SOURCE: "v1"}
420+
d2 = {NONSOURCE: "v2"}
421+
422+
def f(p1,p2):
423+
SINK(p1) #$ MISSING: flow="SOURCE, l:-4 -> p1"
424+
SINK_F(p2)
425+
426+
return p1,p2
427+
428+
rl = list(map(f, d1, d2))
429+
SINK(rl[0][0]) #$ MISSING: flow="SOURCE, l:-10 -> rl[0][0]"
430+
SINK_F(rl[0][1])
431+
432+
### filter
433+
434+
@expects(2)
435+
def test_filter_list():
436+
l = [SOURCE]
437+
438+
def f(p):
439+
SINK(p) #$ flow="SOURCE, l:-3 -> p"
440+
return True
441+
442+
rl = list(filter(f,l))
443+
SINK(rl[0]) #$ flow="SOURCE, l:-7 -> rl[0]"
444+
445+
@expects(2)
446+
def test_filter_set():
447+
s = {SOURCE}
448+
449+
def f(p):
450+
SINK(p) #$ flow="SOURCE, l:-3 -> p"
451+
return True
452+
453+
rl = list(filter(f,s))
454+
SINK(rl[0]) #$ flow="SOURCE, l:-7 -> rl[0]"
455+
456+
@expects(2)
457+
def test_filter_tuple():
458+
t = (SOURCE,)
459+
460+
def f(p):
461+
SINK(p) #$ flow="SOURCE, l:-3 -> p"
462+
return True
463+
464+
rl = list(filter(f,t))
465+
SINK(rl[0]) #$ flow="SOURCE, l:-7 -> rl[0]"
466+
467+
@expects(2)
468+
def test_filter_dict():
469+
d = {SOURCE: "v"}
470+
471+
def f(p):
472+
SINK(p) #$ MISSING: flow="SOURCE, l:-3 -> p"
473+
return True
474+
475+
rl = list(filter(f,d))
476+
SINK(rl[0]) #$ MISSING: flow="SOURCE, l:-7 -> rl[0]"

python/ql/test/library-tests/dataflow/variable-capture/test_library_calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ def set(x):
4545
for x in map(set, [1]):
4646
pass
4747

48-
SINK(captured["x"]) #$ MISSING: captured
48+
SINK(captured["x"]) #$ captured

0 commit comments

Comments
 (0)