Skip to content

Commit 20b188f

Browse files
authored
Merge pull request #11020 from rdmarsh2/rdmarsh2/repair-365-days-per-year
C++: repair Adding365DaysPerYear.ql
2 parents 42e8ec3 + f6ff9c9 commit 20b188f

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import cpp
6-
import semmle.code.cpp.dataflow.DataFlow
6+
import semmle.code.cpp.dataflow.TaintTracking
77
import semmle.code.cpp.commons.DateTime
88

99
/**
@@ -246,26 +246,29 @@ class FiletimeYearArithmeticOperationCheckConfiguration extends DataFlow::Config
246246
}
247247

248248
/**
249-
* `DataFlow::Configuration` for finding an operation with hardcoded 365 that will flow into any known date/time field.
249+
* Taint configuration for finding an operation with hardcoded 365 that will flow into any known date/time field.
250250
*/
251-
class PossibleYearArithmeticOperationCheckConfiguration extends DataFlow::Configuration {
251+
class PossibleYearArithmeticOperationCheckConfiguration extends TaintTracking::Configuration {
252252
PossibleYearArithmeticOperationCheckConfiguration() {
253253
this = "PossibleYearArithmeticOperationCheckConfiguration"
254254
}
255255

256256
override predicate isSource(DataFlow::Node source) {
257-
exists(Operation op | op = source.asExpr() |
257+
exists(Operation op | op = source.asConvertedExpr() |
258258
op.getAChild*().getValue().toInt() = 365 and
259-
not op.getParent() instanceof Expr
259+
(
260+
not op.getParent() instanceof Expr or
261+
op.getParent() instanceof Assignment
262+
)
260263
)
261264
}
262265

263-
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
266+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
264267
// flow from anything on the RHS of an assignment to a time/date structure to that
265268
// assignment.
266-
exists(StructLikeClass dds, FieldAccess fa, AssignExpr aexpr, Expr e |
269+
exists(StructLikeClass dds, FieldAccess fa, Assignment aexpr, Expr e |
267270
e = node1.asExpr() and
268-
aexpr = node2.asExpr()
271+
fa = node2.asExpr()
269272
|
270273
(dds instanceof PackedTimeType or dds instanceof UnpackedTimeType) and
271274
fa.getQualifier().getUnderlyingType() = dds and
@@ -275,7 +278,9 @@ class PossibleYearArithmeticOperationCheckConfiguration extends DataFlow::Config
275278
}
276279

277280
override predicate isSink(DataFlow::Node sink) {
278-
exists(StructLikeClass dds, FieldAccess fa, AssignExpr aexpr | aexpr = sink.asExpr() |
281+
exists(StructLikeClass dds, FieldAccess fa, AssignExpr aexpr |
282+
aexpr.getRValue() = sink.asConvertedExpr()
283+
|
279284
(dds instanceof PackedTimeType or dds instanceof UnpackedTimeType) and
280285
fa.getQualifier().getUnderlyingType() = dds and
281286
fa.isModified() and
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.cpp:173:29:173:51 | ... & ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:170:16:170:47 | ... * ... | ... * ... |
2+
| test.cpp:174:30:174:45 | ... >> ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:170:16:170:47 | ... * ... | ... * ... |
3+
| test.cpp:193:15:193:24 | ... / ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:193:15:193:24 | ... / ... | ... / ... |
4+
| test.cpp:217:29:217:51 | ... & ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:214:16:214:47 | ... * ... | ... * ... |
5+
| test.cpp:218:30:218:45 | ... >> ... | An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios. | test.cpp:214:16:214:47 | ... * ... | ... * ... |

0 commit comments

Comments
 (0)