[PATCH 0/1] MR9988: msvcrt time: add overflow checks for avoiding year 2038 problem
There have already been type overflow checks in same code time.c, but they are not enough. https://gitlab.winehq.org/wine/wine/-/blob/master/dlls/msvcrt/time.c#L336-36... References: - https://en.wikipedia.org/wiki/Year_2038_problem - https://www.gnu.org/software/gnulib/manual/html_node/Avoiding-the-year-2038-... -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9988
From: Herman Semenoff <GermanAizek@yandex.ru> References: https://en.wikipedia.org/wiki/Year_2038_problem https://www.gnu.org/software/gnulib/manual/html_node/Avoiding-the-year-2038-... --- dlls/msvcrt/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 8199fe01649..05999f12116 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -758,7 +758,7 @@ void CDECL _ftime32(struct __timeb32 *buf) struct __timeb64 buf64; _ftime64( &buf64 ); - buf->time = buf64.time; + buf->time = (buf64.time == (__time32_t)buf64.time) ? (__time32_t)buf64.time : -1; buf->millitm = buf64.millitm; buf->timezone = buf64.timezone; buf->dstflag = buf64.dstflag; @@ -798,7 +798,7 @@ __time32_t CDECL _time32(__time32_t *buf) _ftime64(&tb); - curtime = tb.time; + curtime = (tb.time == (__time32_t)tb.time) ? (__time32_t)tb.time : -1; return buf ? *buf = curtime : curtime; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9988
Piotr Caban (@piotr) commented about dlls/msvcrt/time.c:
struct __timeb64 buf64;
_ftime64( &buf64 ); - buf->time = buf64.time; + buf->time = (buf64.time == (__time32_t)buf64.time) ? (__time32_t)buf64.time : -1;
This change doesn't match with native ucrtbase - `buf->time` should overflow as in current code. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9988#note_128283
Piotr Caban (@piotr) commented about dlls/msvcrt/time.c:
_ftime64(&tb);
- curtime = tb.time; + curtime = (tb.time == (__time32_t)tb.time) ? (__time32_t)tb.time : -1;
This change matches with native behavior (tested with ucrtbase). There's unneeded cast: ```suggestion:-0+0 curtime = (tb.time == (__time32_t)tb.time) ? tb.time : -1; ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9988#note_128284
This merge request was closed by Piotr Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9988
Part of the changes were merged as !10169. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9988#note_130348
participants (3)
-
Herman Semenoff -
Herman Semenov (@GermanAizek) -
Piotr Caban (@piotr)