-
Notifications
You must be signed in to change notification settings - Fork 423
Open
Labels
bugSomething isn't workingSomething isn't working
Description
The implementation of mktime in arceos/ulib/axlibc/src/mktime.rs is not fully consistent with the ISO C standard and also contains a potential out-of-bounds access issue. Reference for the ISO C standard behavior: https://en.cppreference.com/w/cpp/chrono/c/mktime.
- Missing Normalization. The implementation of mktime in
arceos/ulib/axlibc/src/mktime.rsdoes not normalize the inputt: *mut ctypes::tmbefore processing. The ISO C standard permits the tm fields to hold arbitrary values, even values outside their normal ranges. While the ISO standard itself does not define behavior for such cases, POSIX requires mktime to normalize the input to produce a valid result. Another strong reason to fix this problem is that the current implementation can trigger an out-of-bounds memory access. It directly indexesMONTH_DAYSbased on (*t).tm_mon, which can exceed 11 whentm_mon >= 12, leading to unsafe memory access. - Missing expected behaviors. According to the ISO C standard, “If the conversion is successful, the time object is modified. All fields of time are updated to fit their proper ranges. time->tm_wday and time->tm_yday are recalculated using information available in other fields.” “A negative value of time->tm_isdst causes mktime to attempt to determine if Daylight Saving Time was in effect.” However, these expected behaviors are currently not implemented.
- O(year) time complexity. The current implementation exhibits O(year) time complexity because it computes day offsets year by year. An attacker could supply an excessively large
tm_yearvalue, causing the application program to hang or severely degrade performance.
Copilot
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working