Python: Move `ModificationOfParameterWithDefault` to new dataflow API · github/codeql@ce63358 · GitHub
Skip to content

Commit ce63358

Browse files
committed
Python: Move ModificationOfParameterWithDefault to new dataflow API
1 parent e8e8d97 commit ce63358

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎python/ql/src/Functions/ModificationOfParameterWithDefault.ql‎

Lines changed: 4 additions & 4 deletions

‎python/ql/src/semmle/python/functions/ModificationOfParameterWithDefault.qll‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ module ModificationOfParameterWithDefault {
1616
import ModificationOfParameterWithDefaultCustomizations::ModificationOfParameterWithDefault
1717

1818
/**
19+
* DEPRECATED: Use `Flow` module instead.
20+
*
1921
* A data-flow configuration for detecting modifications of a parameters default value.
2022
*/
21-
class Configuration extends DataFlow::Configuration {
23+
deprecated class Configuration extends DataFlow::Configuration {
2224
/** Record whether the default value being tracked is non-empty. */
2325
boolean nonEmptyDefault;
2426

@@ -43,4 +45,33 @@ module ModificationOfParameterWithDefault {
4345
nonEmptyDefault = false and node instanceof MustBeNonEmpty
4446
}
4547
}
48+
49+
private module Config implements DataFlow::StateConfigSig {
50+
class FlowState = boolean;
51+
52+
predicate isSource(DataFlow::Node source, FlowState state) {
53+
source.(Source).isNonEmpty() = state
54+
}
55+
56+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
57+
58+
predicate isSink(DataFlow::Node sink, FlowState state) {
59+
// dummy implementation since this predicate is required, but actual logic is in
60+
// the predicate above.
61+
none()
62+
}
63+
64+
predicate isBarrier(DataFlow::Node node, FlowState state) {
65+
// if we are tracking a non-empty default, then it is ok to modify empty values,
66+
// so our tracking ends at those.
67+
state = true and node instanceof MustBeEmpty
68+
or
69+
// if we are tracking a empty default, then it is ok to modify non-empty values,
70+
// so our tracking ends at those.
71+
state = false and node instanceof MustBeNonEmpty
72+
}
73+
}
74+
75+
/** Global data-flow for detecting modifications of a parameters default value. */
76+
module Flow = DataFlow::GlobalWithState<Config>;
4677
}

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

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)