|
| 1 | +def from_keywords(): |
| 2 | + frozen = frozendict(tainted=SOURCE, clean=NONSOURCE) |
| 3 | + SINK(frozen["tainted"]) # $ flow="SOURCE, l:-1 -> frozen['tainted']" |
| 4 | + SINK_F(frozen["clean"]) |
| 5 | + |
| 6 | + |
| 7 | +def from_mapping(): |
| 8 | + frozen = frozendict({"tainted": SOURCE, "clean": NONSOURCE}, extra=NONSOURCE) |
| 9 | + SINK(frozen["tainted"]) # $ flow="SOURCE, l:-1 -> frozen['tainted']" |
| 10 | + SINK_F(frozen["clean"]) |
| 11 | + SINK_F(frozen["extra"]) |
| 12 | + |
| 13 | + |
| 14 | +def from_pairs(): |
| 15 | + frozen = frozendict([("key", SOURCE)]) |
| 16 | + SINK(frozen["key"]) # $ flow="SOURCE, l:-1 -> frozen['key']" |
| 17 | + |
| 18 | + |
| 19 | +def from_frozendict(): |
| 20 | + original = frozendict(tainted=SOURCE, clean=NONSOURCE) |
| 21 | + frozen = frozendict(original) |
| 22 | + SINK(frozen["tainted"]) # $ flow="SOURCE, l:-2 -> frozen['tainted']" |
| 23 | + SINK_F(frozen["clean"]) |
| 24 | + |
| 25 | + |
| 26 | +def from_unpacked_keywords(): |
| 27 | + frozen = frozendict(**{"tainted": SOURCE, "clean": NONSOURCE}) |
| 28 | + SINK(frozen["tainted"]) # $ MISSING: flow="SOURCE, l:-1 -> frozen['tainted']" |
| 29 | + SINK_F(frozen["clean"]) |
| 30 | + |
| 31 | + # Keyword unpacking has the same limitation for dict. |
| 32 | + mutable = dict(**{"tainted": SOURCE, "clean": NONSOURCE}) |
| 33 | + SINK(mutable["tainted"]) # $ MISSING: flow="SOURCE, l:-1 -> mutable['tainted']" |
| 34 | + SINK_F(mutable["clean"]) |
| 35 | + |
| 36 | + |
| 37 | +def nested_contents(): |
| 38 | + frozen = frozendict(nested={"key": SOURCE}) |
| 39 | + SINK(frozen["nested"]["key"]) # $ flow="SOURCE, l:-1 -> frozen['nested']['key']" |
| 40 | + |
| 41 | + |
| 42 | +def qualified_constructor(): |
| 43 | + import builtins |
| 44 | + frozen = builtins.frozendict(key=SOURCE) |
| 45 | + SINK(frozen["key"]) # $ flow="SOURCE, l:-1 -> frozen['key']" |
| 46 | + |
| 47 | + |
| 48 | +def imported_constructor(): |
| 49 | + from builtins import frozendict as freeze |
| 50 | + frozen = freeze(key=SOURCE) |
| 51 | + SINK(frozen["key"]) # $ flow="SOURCE, l:-1 -> frozen['key']" |
| 52 | + |
| 53 | + |
| 54 | +def aliased_constructor(): |
| 55 | + freeze = frozendict |
| 56 | + frozen = freeze(key=SOURCE) |
| 57 | + SINK(frozen["key"]) # $ flow="SOURCE, l:-1 -> frozen['key']" |
| 58 | + |
| 59 | + |
| 60 | +def constructor_callback(): |
| 61 | + frozen = next(map(frozendict, [{"key": SOURCE}])) |
| 62 | + SINK(frozen["key"]) # $ flow="SOURCE, l:-1 -> frozen['key']" |
| 63 | + |
| 64 | + |
| 65 | +def mapping_methods(): |
| 66 | + frozen = frozendict(tainted=SOURCE, clean=NONSOURCE) |
| 67 | + SINK(frozen.get("tainted")) # $ flow="SOURCE, l:-1 -> frozen.get(..)" |
| 68 | + SINK_F(frozen.get("clean")) |
| 69 | + SINK_F(frozen.get("missing")) |
| 70 | + |
| 71 | + copied = frozen.copy() |
| 72 | + SINK(copied["tainted"]) # $ flow="SOURCE, l:-6 -> copied['tainted']" |
| 73 | + SINK_F(copied["clean"]) |
| 74 | + |
| 75 | + values = list(frozen.values()) |
| 76 | + SINK(values[0]) # $ flow="SOURCE, l:-10 -> values[0]" |
| 77 | + |
| 78 | + items = list(frozen.items()) |
| 79 | + SINK(items[0][1]) # $ flow="SOURCE, l:-13 -> items[0][1]" |
| 80 | + SINK_F(items[0][0]) |
| 81 | + |
| 82 | + |
| 83 | +def copied_contents(): |
| 84 | + original = {"key": SOURCE} |
| 85 | + frozen = frozendict(original) |
| 86 | + original["key"] = NONSOURCE |
| 87 | + SINK(frozen["key"]) # $ flow="SOURCE, l:-3 -> frozen['key']" |
| 88 | + SINK_F(original["key"]) |
| 89 | + |
| 90 | + |
| 91 | +def shadowed_constructor(): |
| 92 | + def frozendict(**kwargs): |
| 93 | + return {"key": NONSOURCE} |
| 94 | + |
| 95 | + frozen = frozendict(key=SOURCE) |
| 96 | + SINK_F(frozen["key"]) |
0 commit comments