Skip to content

Commit 913990b

Browse files
committed
Python: Add suggested comments and test case
1 parent c6eb795 commit 913990b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module ModificationOfParameterWithDefault {
1717
* A data flow source for detecting modifications of a parameters default value.
1818
*/
1919
abstract class Source extends DataFlow::Node {
20+
/** Result is true if the default value is non-empty for this source and false if not. */
2021
abstract boolean isNonEmpty();
2122
}
2223

@@ -34,6 +35,7 @@ module ModificationOfParameterWithDefault {
3435
* A sanitizer guard for detecting modifications of a parameters default value.
3536
*/
3637
abstract class BarrierGuard extends DataFlow::BarrierGuard {
38+
/** Result is true if this guard blocks non-empty values and false if it blocks empty values. */
3739
abstract boolean blocksNonEmpty();
3840
}
3941

@@ -120,7 +122,7 @@ module ModificationOfParameterWithDefault {
120122
}
121123
}
122124

123-
/**
125+
/**
124126
* An expression that is checked directly in an `if`, possibly with `not`, such as `if x:` or `if not x:`.
125127
*/
126128
private class IdentityGuarded extends Expr {
@@ -139,7 +141,7 @@ module ModificationOfParameterWithDefault {
139141
)
140142
}
141143

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,11 @@ def dict_update_op_nochange(d = {}):
124124
# OK
125125
def sanitizer(l = []):
126126
if l:
127+
l.append(1) #$ modification=l
128+
return l
129+
130+
# OK
131+
def sanitizer_negated(l = [1]):
132+
if not l:
127133
l.append(1) #$ SPURIOUS: modification=l
128134
return l

0 commit comments

Comments
 (0)