Skip to content

Commit c6eb795

Browse files
yoffRasmusWL
andauthored
Apply suggestions from code review
Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent a855074 commit c6eb795

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

python/ql/src/semmle/python/functions/ModificationOfParameterWithDefaultCustomizations.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module ModificationOfParameterWithDefault {
5353
}
5454

5555
/**
56-
* A source of remote user input, considered as a flow source.
56+
* A mutable default value for a parameter, considered as a flow source.
5757
*/
5858
class MutableDefaultValue extends Source {
5959
boolean nonEmpty;
@@ -120,6 +120,9 @@ module ModificationOfParameterWithDefault {
120120
}
121121
}
122122

123+
/**
124+
* An expression that is checked directly in an `if`, possibly with `not`, such as `if x:` or `if not x:`.
125+
*/
123126
private class IdentityGuarded extends Expr {
124127
boolean inverted;
125128

@@ -136,6 +139,9 @@ module ModificationOfParameterWithDefault {
136139
)
137140
}
138141

142+
/**
143+
* Whether this guard has been inverted. For `if x:` the result is `false`, and for `if not x:` the result is `true`.
144+
*/
139145
boolean isInverted() { result = inverted }
140146
}
141147

python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def list_del(l = [0]):
1515

1616
# Not OK
1717
def append_op(l = []):
18-
l += 1 #$ modification=l
18+
l += [1, 2, 3] #$ modification=l
1919
return l
2020

2121
# Not OK
@@ -123,6 +123,6 @@ def dict_update_op_nochange(d = {}):
123123

124124
# OK
125125
def sanitizer(l = []):
126-
if not l == []:
126+
if l:
127127
l.append(1) #$ SPURIOUS: modification=l
128128
return l

0 commit comments

Comments
 (0)