Skip to content

Commit 6d7bd97

Browse files
committed
Check for leap day
1 parent c94edcf commit 6d7bd97

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,55 @@ class StructTmLeapYearFieldAccess extends LeapYearFieldAccess {
380380
}
381381
}
382382

383+
/**
384+
* `stDate.wMonth == 2`
385+
*/
386+
class DateCheckMonthFebruary extends Operation {
387+
DateCheckMonthFebruary(){
388+
this.getOperator() = "==" and
389+
this.getAnOperand() instanceof MonthFieldAccess and
390+
this.getAnOperand().(Literal).getValue() = "2"
391+
}
392+
393+
Expr getDateQualifier(){
394+
result = this.getAnOperand().(MonthFieldAccess).getQualifier()
395+
}
396+
}
397+
398+
/**
399+
* `stDate.wDay == 29`
400+
*/
401+
class DateCheckDay29 extends Operation {
402+
DateCheckDay29(){
403+
this.getOperator() = "==" and
404+
this.getAnOperand() instanceof DayFieldAccess and
405+
this.getAnOperand().(Literal).getValue() = "29"
406+
}
407+
408+
Expr getDateQualifier(){
409+
result = this.getAnOperand().(DayFieldAccess).getQualifier()
410+
}
411+
}
412+
413+
/**
414+
* The combination of a February and Day 29 verification
415+
* `stDate.wMonth == 2 && stDate.wDay == 29`
416+
*/
417+
class DateFebruary29Check extends Operation {
418+
DateFebruary29Check(){
419+
this.getOperator() = "&&" and
420+
exists(DateCheckMonthFebruary checkFeb, DateCheckDay29 check29 |
421+
checkFeb = this.getAnOperand() and
422+
check29 = this.getAnOperand() and
423+
hashCons(checkFeb.getDateQualifier()) = hashCons(check29.getDateQualifier())
424+
)
425+
}
426+
427+
Expr getDateQualifier(){
428+
result = this.getAnOperand().(DateCheckMonthFebruary).getDateQualifier()
429+
}
430+
}
431+
383432
/**
384433
* `Function` that includes an operation that is checking for leap year.
385434
*/

cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModificationPrecise.ql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ predicate isYearModifiedWithCheck(YearFieldAccess fa) {
280280
src.isSource() and
281281
src.getNode().asExpr() = fa
282282
)
283+
or
284+
isUsedInFeb29Check(fa)
285+
}
286+
287+
/**
288+
* If there is a flow from a date struct year field access/assignment to a Feb 29 check
289+
*/
290+
predicate isUsedInFeb29Check(YearFieldAccess fa){
291+
exists(DateFebruary29Check check |
292+
DataFlow::localExprFlow(fa.getQualifier(), check.getDateQualifier())
293+
or
294+
DataFlow::localExprFlow(check.getDateQualifier(), fa.getQualifier())
295+
)
283296
}
284297

285298
import OperationToYearAssignmentFlow::PathGraph

0 commit comments

Comments
 (0)