Skip to content

Commit 95d4a54

Browse files
committed
C++: Refactor leap year logic for UncheckedLeapYearAfterYearModification. Includes new logic for detecting leap year checks, new forms of leap year checks detected, and various heuristics to remove false postives. Move TimeConversionFunction into LeapYear.qll and refactored to separate conversion functions that are expected to be checked for failure from those that auto correct leap year dates if feb 29 is provided on a non-leap year. Increas the set of known TimeConversionFunctions.
1 parent 6c171c8 commit 95d4a54

File tree

3 files changed

+850
-50
lines changed

3 files changed

+850
-50
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,35 @@ private module PossibleYearArithmeticOperationCheckConfig implements DataFlow::C
308308

309309
module PossibleYearArithmeticOperationCheckFlow =
310310
TaintTracking::Global<PossibleYearArithmeticOperationCheckConfig>;
311+
312+
/**
313+
* This list of APIs should check for the return value to detect problems during the conversion.
314+
*/
315+
class TimeConversionFunction extends Function {
316+
boolean autoLeapYearCorrecting;
317+
318+
TimeConversionFunction() {
319+
autoLeapYearCorrecting = false and
320+
(
321+
this.getName() =
322+
[
323+
"FileTimeToSystemTime", "SystemTimeToFileTime", "SystemTimeToTzSpecificLocalTime",
324+
"SystemTimeToTzSpecificLocalTimeEx", "TzSpecificLocalTimeToSystemTime",
325+
"TzSpecificLocalTimeToSystemTimeEx", "RtlLocalTimeToSystemTime",
326+
"RtlTimeToSecondsSince1970", "_mkgmtime", "SetSystemTime", "VarUdateFromDate", "from_tm"
327+
]
328+
or
329+
// Matches all forms of GetDateFormat, e.g. GetDateFormatA/W/Ex
330+
this.getName().matches("GetDateFormat%")
331+
)
332+
or
333+
autoLeapYearCorrecting = true and
334+
this.getName() =
335+
["mktime", "_mktime32", "_mktime64", "SystemTimeToVariantTime", "VariantTimeToSystemTime"]
336+
}
337+
338+
/**
339+
* Holds if the function is expected to auto convert a bad leap year date.
340+
*/
341+
predicate isAutoLeapYearCorrecting() { autoLeapYearCorrecting = true }
342+
}

0 commit comments

Comments
 (0)