mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Python: Move ModificationOfParameterWithDefault to new dataflow API
This commit is contained in:
@@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import semmle.python.functions.ModificationOfParameterWithDefault
|
import semmle.python.functions.ModificationOfParameterWithDefault
|
||||||
import DataFlow::PathGraph
|
import ModificationOfParameterWithDefault::Flow::PathGraph
|
||||||
|
|
||||||
from
|
from
|
||||||
ModificationOfParameterWithDefault::Configuration config, DataFlow::PathNode source,
|
ModificationOfParameterWithDefault::Flow::PathNode source,
|
||||||
DataFlow::PathNode sink
|
ModificationOfParameterWithDefault::Flow::PathNode sink
|
||||||
where config.hasFlowPath(source, sink)
|
where ModificationOfParameterWithDefault::Flow::flowPath(source, sink)
|
||||||
select sink.getNode(), source, sink, "This expression mutates a $@.", source.getNode(),
|
select sink.getNode(), source, sink, "This expression mutates a $@.", source.getNode(),
|
||||||
"default value"
|
"default value"
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ module ModificationOfParameterWithDefault {
|
|||||||
import ModificationOfParameterWithDefaultCustomizations::ModificationOfParameterWithDefault
|
import ModificationOfParameterWithDefaultCustomizations::ModificationOfParameterWithDefault
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* DEPRECATED: Use `Flow` module instead.
|
||||||
|
*
|
||||||
* A data-flow configuration for detecting modifications of a parameters default value.
|
* A data-flow configuration for detecting modifications of a parameters default value.
|
||||||
*/
|
*/
|
||||||
class Configuration extends DataFlow::Configuration {
|
deprecated class Configuration extends DataFlow::Configuration {
|
||||||
/** Record whether the default value being tracked is non-empty. */
|
/** Record whether the default value being tracked is non-empty. */
|
||||||
boolean nonEmptyDefault;
|
boolean nonEmptyDefault;
|
||||||
|
|
||||||
@@ -43,4 +45,33 @@ module ModificationOfParameterWithDefault {
|
|||||||
nonEmptyDefault = false and node instanceof MustBeNonEmpty
|
nonEmptyDefault = false and node instanceof MustBeNonEmpty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private module Config implements DataFlow::StateConfigSig {
|
||||||
|
class FlowState = boolean;
|
||||||
|
|
||||||
|
predicate isSource(DataFlow::Node source, FlowState state) {
|
||||||
|
source.(Source).isNonEmpty() = state
|
||||||
|
}
|
||||||
|
|
||||||
|
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
|
||||||
|
|
||||||
|
predicate isSink(DataFlow::Node sink, FlowState state) {
|
||||||
|
// dummy implementation since this predicate is required, but actual logic is in
|
||||||
|
// the predicate above.
|
||||||
|
none()
|
||||||
|
}
|
||||||
|
|
||||||
|
predicate isBarrier(DataFlow::Node node, FlowState state) {
|
||||||
|
// if we are tracking a non-empty default, then it is ok to modify empty values,
|
||||||
|
// so our tracking ends at those.
|
||||||
|
state = true and node instanceof MustBeEmpty
|
||||||
|
or
|
||||||
|
// if we are tracking a empty default, then it is ok to modify non-empty values,
|
||||||
|
// so our tracking ends at those.
|
||||||
|
state = false and node instanceof MustBeNonEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Global data-flow for detecting modifications of a parameters default value. */
|
||||||
|
module Flow = DataFlow::GlobalWithState<Config>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module ModificationOfParameterWithDefaultTest implements TestSig {
|
|||||||
string getARelevantTag() { result = "modification" }
|
string getARelevantTag() { result = "modification" }
|
||||||
|
|
||||||
private predicate relevant_node(DataFlow::Node sink) {
|
private predicate relevant_node(DataFlow::Node sink) {
|
||||||
exists(ModificationOfParameterWithDefault::Configuration cfg | cfg.hasFlowTo(sink))
|
ModificationOfParameterWithDefault::Flow::flowTo(sink)
|
||||||
}
|
}
|
||||||
|
|
||||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user