Skip to content

Commit 382b3ce

Browse files
committed
Python: conversion step for format_map
and adjust collection test
1 parent 12fc379 commit 382b3ce

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,12 @@ module Conversions {
10251025
fmt.getRight() = nodeFrom.asCfgNode()
10261026
) and
10271027
c instanceof TupleElementContent
1028+
or
1029+
// format_map
1030+
// see https://docs.python.org/3/library/stdtypes.html#str.format_map
1031+
nodeTo.(MethodCallNode).calls(_, "format_map") and
1032+
nodeTo.(MethodCallNode).getArg(0) = nodeFrom and
1033+
c instanceof DictionaryElementContent
10281034
}
10291035

10301036
predicate readStep(Node nodeFrom, ContentSet c, Node nodeTo) {

python/ql/test/library-tests/dataflow/tainttracking/defaultAdditionalTaintStep-py3/test_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def str_methods():
1717
ts.casefold(), # $ tainted
1818

1919
ts.format_map({}), # $ tainted
20-
"{unsafe}".format_map({"unsafe": ts}), # $ MISSING: tainted
20+
"{unsafe}".format_map({"unsafe": ts}), # $ tainted
2121
)
2222

2323

python/ql/test/library-tests/dataflow/tainttracking/defaultAdditionalTaintStep/test_collections.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ def test_construction():
2727
tainted_dict, # $ tainted
2828
)
2929

30+
# There are no implicit reads for list content as it is imprecise
31+
# Therefore, list content stemming from precise content does not end up on the list itself.
3032
ensure_tainted(
3133
list(tainted_list), # $ tainted
32-
list(tainted_tuple), # $ MISSING: tainted
34+
list(tainted_tuple)[0], # $ tainted
3335
list(tainted_set), # $ tainted
34-
list(tainted_dict.values()), # $ MISSING: tainted
35-
list(tainted_dict.items()), # $ MISSING: tainted
36+
list(tainted_dict.values())[0], # $ tainted
37+
list(tainted_dict.items())[0], # $ tainted
3638

3739
tuple(tainted_list), # $ tainted
3840
set(tainted_list), # $ tainted

0 commit comments

Comments
 (0)