C#: Re-factor UnsafeYearConstruction to use the new API.

This commit is contained in:
Michael Nebel
2023-04-13 14:42:03 +02:00
parent eb7e401aea
commit 5601ad64ef

View File

@@ -10,21 +10,17 @@
*/
import csharp
import DataFlow::PathGraph
import UnsafeYearCreationFromArithmetic::PathGraph
class UnsafeYearCreationFromArithmeticConfiguration extends TaintTracking::Configuration {
UnsafeYearCreationFromArithmeticConfiguration() {
this = "UnsafeYearCreationFromArithmeticConfiguration"
}
override predicate isSource(DataFlow::Node source) {
module UnsafeYearCreationFromArithmeticConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
exists(ArithmeticOperation ao, PropertyAccess pa | ao = source.asExpr() |
pa = ao.getAChild*() and
pa.getProperty().hasQualifiedName("System.DateTime", "Year")
)
}
override predicate isSink(DataFlow::Node sink) {
predicate isSink(DataFlow::Node sink) {
exists(ObjectCreation oc |
sink.asExpr() = oc.getArgumentForName("year") and
oc.getObjectType().getABaseType*().hasQualifiedName("System", "DateTime")
@@ -32,10 +28,12 @@ class UnsafeYearCreationFromArithmeticConfiguration extends TaintTracking::Confi
}
}
module UnsafeYearCreationFromArithmetic =
TaintTracking::Global<UnsafeYearCreationFromArithmeticConfig>;
from
UnsafeYearCreationFromArithmeticConfiguration config, DataFlow::PathNode source,
DataFlow::PathNode sink
where config.hasFlowPath(source, sink)
UnsafeYearCreationFromArithmetic::PathNode source, UnsafeYearCreationFromArithmetic::PathNode sink
where UnsafeYearCreationFromArithmetic::flowPath(source, sink)
select sink, source, sink,
"This $@ based on a 'System.DateTime.Year' property is used in a construction of a new 'System.DateTime' object, flowing to the 'year' argument.",
source, "arithmetic operation"