From 84faf49bf0d63f19dc43619ef2ccfaa1ef3f8be2 Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Tue, 20 Sep 2022 14:28:44 +0200 Subject: [PATCH] Python: Add tests for compound arguments field flow --- .../experimental/dataflow/fieldflow/test.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/python/ql/test/experimental/dataflow/fieldflow/test.py b/python/ql/test/experimental/dataflow/fieldflow/test.py index d9cb0280c73..100ab6aac70 100644 --- a/python/ql/test/experimental/dataflow/fieldflow/test.py +++ b/python/ql/test/experimental/dataflow/fieldflow/test.py @@ -193,6 +193,39 @@ def test_nested_obj_method(): SINK(a.obj.foo) # $ flow="SOURCE, l:-3 -> a.obj.foo" +# ------------------------------------------------------------------------------ +# Field access on compound arguments +# ------------------------------------------------------------------------------ + +# TODO: Add support for this, see https://github.com/github/codeql/pull/10444 + +@expects(5) # $ unresolved_call=expects(..) unresolved_call=expects(..)(..) +def test_field_on_compound_arg(cond_true=True, cond_false=False): + class Ex: + def __init__(self): + self.attr = None + + def set_attr(obj): + obj.attr = SOURCE + + x = Ex() + y = Ex() + set_attr(x if cond_true else y) + SINK(x.attr) # $ MISSING: flow + + x = Ex() + y = Ex() + set_attr(x if cond_false else y) + SINK(y.attr) # $ MISSING: flow + + x = Ex() + y = Ex() + z = Ex() + set_attr(x if cond_false else (y if cond_true else z)) + SINK_F(x.attr) # $ MISSING: flow + SINK(y.attr) # $ MISSING: flow + SINK_F(z.attr) # $ MISSING: flow + # ------------------------------------------------------------------------------ # Crosstalk test -- using different function based on conditional # ------------------------------------------------------------------------------