...
This noncompliant code example is adapted from C code that appeared in the Zune 30 media player, causing many players to lock up on December 30, 2008, at midnight PST. It contains incomplete logic that causes a denial of service when converting dates.
Code Block | ||
---|---|---|
| ||
final static int ORIGIN_YEAR = 1980; UINT32long days = /* number of days since January 1, 1980 */ int year = ORIGIN_YEAR; /* ... */ while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } } else { days -= 365; year += 1; } } |
...
Code Block | ||
---|---|---|
| ||
final static int ORIGIN_YEAR = 1980; UINT32long days = /* number of days since January 1, 1980 */ int year = ORIGINYEAR; /* ... */ int daysThisYear = (IsLeapYear(year) ? 366 : 365); while (days > daysThisYear) { days -= daysThisYear; year += 1; daysThisYear = (IsLeapYear(year) ? 366 : 365); } |
...