From ffc27b530181387355346b7991bfdf396ef8e12d Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Mon, 13 Nov 2023 10:47:48 +0100 Subject: [PATCH] Python: Solve problems with missing TTupleElementContent Ruby uses 10 as their number. I considered doing the same, but didn't really care _too_ much about it :shrug: https://github.com/github/codeql/blob/14cfb82a8c16e15fadc006ae46331302f0341f63/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll#L636 --- .../semmle/python/dataflow/new/internal/DataFlowPublic.qll | 5 +++++ .../dataflow/summaries-checks/invalid-spec.expected | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll b/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll index 0593ba85e70..287a677c5ef 100644 --- a/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll +++ b/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll @@ -588,6 +588,11 @@ newtype TContent = or // Arguments can overflow and end up in the starred parameter tuple. exists(any(CallNode cn).getArg(index)) + or + // since flow summaries might use tuples, we ensure that we at least have valid + // TTupleElementContent for the 0..7 (7 was picked to match `small_tuple` in + // data-flow-private) + index in [0 .. 7] } or /** An element of a dictionary under a specific key. */ TDictionaryElementContent(string key) { diff --git a/python/ql/test/experimental/dataflow/summaries-checks/invalid-spec.expected b/python/ql/test/experimental/dataflow/summaries-checks/invalid-spec.expected index bc342d8091a..e69de29bb2d 100644 --- a/python/ql/test/experimental/dataflow/summaries-checks/invalid-spec.expected +++ b/python/ql/test/experimental/dataflow/summaries-checks/invalid-spec.expected @@ -1,2 +0,0 @@ -| compiled re.subn | ReturnValue.TupleElement[0] | TupleElement[0] | -| re.subn | ReturnValue.TupleElement[0] | TupleElement[0] |