Python: supress non-useful results (w/ tests) for iter str/seq query

Fixes https://github.com/Semmle/ql/issues/3207
This commit is contained in:
Rasmus Wriedt Larsen
2020-04-07 11:27:45 +02:00
parent 94ccc16f85
commit befe73df14
2 changed files with 5 additions and 3 deletions

View File

@@ -12,6 +12,7 @@
*/
import python
import semmle.python.filters.Tests
predicate has_string_type(Value v) {
v.getClass() = ClassValue::str()
@@ -28,7 +29,10 @@ where
iter.pointsTo(seq, seq_origin) and
has_string_type(str) and
seq.getClass().isIterable() and
not has_string_type(seq)
not has_string_type(seq) and
// suppress occurrences from tests
not seq_origin.getScope().getScope*() instanceof TestScope and
not str_origin.getScope().getScope*() instanceof TestScope
select loop,
"Iteration over $@, of class " + seq.getClass().getName() + ", may also iterate over $@.",
seq_origin, "sequence", str_origin, "string"