File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
python/ql/src/semmle/python/functions Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -159,17 +159,26 @@ module ModificationOfParameterWithDefault {
159
159
boolean isInverted ( ) { result = inverted }
160
160
}
161
161
162
+ /**
163
+ * Holds iff `guard` is checking the `Name` represented by `guarded` for truthyness.
164
+ * `result` is true if the check is inverted and false if it is not.
165
+ */
162
166
boolean isIdentityGuard ( DataFlow:: GuardNode guard , ControlFlowNode guarded ) {
163
167
exists ( IdentityGuarded ig |
164
168
ig instanceof Name and
165
169
// In `not l`, the `ControlFlowNode` for `l` is not an instance of `GuardNode`.
166
- // TODO: This is slightly naive, we should change it when we have a proper guards library.
170
+ // TODO: This is slightly naive, not handling e.g. `l or cond` correctly.
171
+ // We should change it when we have a proper guards library.
167
172
guard .getNode ( ) .getAChildNode * ( ) = ig and
168
173
result = ig .isInverted ( ) and
169
174
guarded .getNode ( ) = ig
170
175
)
171
176
}
172
177
178
+ /**
179
+ * A sanitizer guard that does not let a truthy value flow to the true branch.
180
+ * Based on `isIdentityGuard`, so comes with the same caveats.
181
+ */
173
182
class BlocksTruthyGuard extends BlocksTruthy {
174
183
ControlFlowNode guarded ;
175
184
@@ -186,6 +195,10 @@ module ModificationOfParameterWithDefault {
186
195
}
187
196
}
188
197
198
+ /**
199
+ * A sanitizer guard that does not let a falsy value flow to the true branch.
200
+ * Based on `isIdentityGuard`, so comes with the same caveats.
201
+ */
189
202
class BlocksFalseyGuard extends BlocksFalsey {
190
203
ControlFlowNode guarded ;
191
204
You can’t perform that action at this time.
0 commit comments