Skip to content

Commit 5601ad6

Browse files
committed
C#: Re-factor UnsafeYearConstruction to use the new API.
1 parent eb7e401 commit 5601ad6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

csharp/ql/src/Likely Bugs/LeapYear/UnsafeYearConstruction.ql

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,30 @@
1010
*/
1111

1212
import csharp
13-
import DataFlow::PathGraph
13+
import UnsafeYearCreationFromArithmetic::PathGraph
1414

15-
class UnsafeYearCreationFromArithmeticConfiguration extends TaintTracking::Configuration {
16-
UnsafeYearCreationFromArithmeticConfiguration() {
17-
this = "UnsafeYearCreationFromArithmeticConfiguration"
18-
}
19-
20-
override predicate isSource(DataFlow::Node source) {
15+
module UnsafeYearCreationFromArithmeticConfig implements DataFlow::ConfigSig {
16+
predicate isSource(DataFlow::Node source) {
2117
exists(ArithmeticOperation ao, PropertyAccess pa | ao = source.asExpr() |
2218
pa = ao.getAChild*() and
2319
pa.getProperty().hasQualifiedName("System.DateTime", "Year")
2420
)
2521
}
2622

27-
override predicate isSink(DataFlow::Node sink) {
23+
predicate isSink(DataFlow::Node sink) {
2824
exists(ObjectCreation oc |
2925
sink.asExpr() = oc.getArgumentForName("year") and
3026
oc.getObjectType().getABaseType*().hasQualifiedName("System", "DateTime")
3127
)
3228
}
3329
}
3430

31+
module UnsafeYearCreationFromArithmetic =
32+
TaintTracking::Global<UnsafeYearCreationFromArithmeticConfig>;
33+
3534
from
36-
UnsafeYearCreationFromArithmeticConfiguration config, DataFlow::PathNode source,
37-
DataFlow::PathNode sink
38-
where config.hasFlowPath(source, sink)
35+
UnsafeYearCreationFromArithmetic::PathNode source, UnsafeYearCreationFromArithmetic::PathNode sink
36+
where UnsafeYearCreationFromArithmetic::flowPath(source, sink)
3937
select sink, source, sink,
4038
"This $@ based on a 'System.DateTime.Year' property is used in a construction of a new 'System.DateTime' object, flowing to the 'year' argument.",
4139
source, "arithmetic operation"

0 commit comments

Comments
 (0)