Skip to content

Commit 2502d1c

Browse files
authored
Merge pull request github#3410 from RasmusWL/python-fix-3397
Python: More safe methods for py/modification-of-default-value
2 parents 2561ba8 + 5d5d412 commit 2502d1c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

python/ql/src/Functions/ModificationOfParameterWithDefault.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ predicate safe_method(string name) {
2525
name = "values" or
2626
name = "iteritems" or
2727
name = "iterkeys" or
28-
name = "itervalues"
28+
name = "itervalues" or
29+
name = "__contains__" or
30+
name = "__getitem__" or
31+
name = "__getattribute__"
2932
}
3033

3134
/** Gets the truthiness (non emptyness) of the default of `p` if that value is mutable */

python/ql/test/query-tests/Functions/general/functions_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,8 @@ def list_default(x=[1,2,3,4]):
193193

194194
def tuple_default(x=(1,2)):
195195
do_stuff_based_on_type(x)
196+
197+
# Modification of parameter with default (safe method)
198+
199+
def safe_method(x=[]):
200+
return x.count(42)

0 commit comments

Comments
 (0)