From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 395863858D33; Tue, 7 Feb 2023 14:05:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 395863858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675778702; bh=ayElqc2uQ41qrlNnoT8WDYXSCLjxUknYSIinkJBe84Y=; h=From:To:Subject:Date:From; b=Q7go16n8pLwU4+QNkJ5VRhdcLtVZB9WYIQ73qKroiEWQAPpgBuBGeHCmTVDR1U/AL 3JKh1zxqdasYk6uGGXKwSpSn0/L7KcaBIJAwH7JzXQI3W5Ixrk1cjavsRuhfS5jabt mbxEW6AWA0lWW6R7B/gOP4JOJaI76rHXA42rmQpQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/release/2.34/master] Use 64-bit time_t interfaces in strftime and strptime (bug 30053) X-Act-Checkin: glibc X-Git-Author: Andreas Schwab X-Git-Refname: refs/heads/release/2.34/master X-Git-Oldrev: c5c792092b57687ae3ebecbe8645fa71ddb19f8c X-Git-Newrev: 0b962177ee3b45cf775176eb454fcf6aa1b0f6e3 Message-Id: <20230207140502.395863858D33@sourceware.org> Date: Tue, 7 Feb 2023 14:05:02 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0b962177ee3b45cf775176eb454fcf6aa1b0f6e3 commit 0b962177ee3b45cf775176eb454fcf6aa1b0f6e3 Author: Andreas Schwab Date: Thu Jan 26 14:25:05 2023 +0100 Use 64-bit time_t interfaces in strftime and strptime (bug 30053) Both functions use time_t only internally, so the ABI is not affected. (cherry picked from commit 41349f6f67c83e7bafe49f985b56493d2c4c9c77) Diff: --- NEWS | 2 ++ time/Makefile | 3 ++- time/strftime_l.c | 4 ++++ time/strptime_l.c | 4 +++- time/tst-strftime4-time64.c | 1 + time/tst-strftime4.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index d576862346..0da4770fd1 100644 --- a/NEWS +++ b/NEWS @@ -137,6 +137,8 @@ The following bugs are resolved with this release: [29771] Restore IPC_64 support in sysvipc *ctl functions [29776] elf/tst-tlsopt-powerpc fails when compiled with -mcpu=power10 [29951] time: Set daylight to 1 for matching DST/offset change + [30068] stdio: incorrect printf output for integers with thousands + separator and width field (CVE-2023-25139) Version 2.34 diff --git a/time/Makefile b/time/Makefile index 38e3a7f4c7..ef3bb767b8 100644 --- a/time/Makefile +++ b/time/Makefile @@ -50,7 +50,7 @@ tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 \ tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \ tst-settimeofday tst-itimer tst-gmtime tst-timegm \ - tst-timespec_get tst-timespec_getres + tst-timespec_get tst-timespec_getres tst-strftime4 tests-time64 := \ tst-adjtime-time64 \ @@ -65,6 +65,7 @@ tests-time64 := \ tst-itimer-time64 \ tst-mktime4-time64 \ tst-settimeofday-time64 \ + tst-strftime4-time64 \ tst-timegm-time64 \ tst-timespec_get-time64 \ tst-timespec_getres-time64 \ diff --git a/time/strftime_l.c b/time/strftime_l.c index d8cde9c5a3..57abbaa571 100644 --- a/time/strftime_l.c +++ b/time/strftime_l.c @@ -159,6 +159,10 @@ extern char *tzname[]; #ifdef _LIBC # define tzname __tzname # define tzset __tzset + +# define time_t __time64_t +# define __gmtime_r(t, tp) __gmtime64_r (t, tp) +# define mktime(tp) __mktime64 (tp) #endif #if !HAVE_TM_GMTOFF diff --git a/time/strptime_l.c b/time/strptime_l.c index 02c5d63c79..39d1e59b08 100644 --- a/time/strptime_l.c +++ b/time/strptime_l.c @@ -30,8 +30,10 @@ #ifdef _LIBC # define HAVE_LOCALTIME_R 0 # include "../locale/localeinfo.h" -#endif +# define time_t __time64_t +# define __localtime_r(t, tp) __localtime64_r (t, tp) +#endif #if ! HAVE_LOCALTIME_R && ! defined localtime_r # ifdef _LIBC diff --git a/time/tst-strftime4-time64.c b/time/tst-strftime4-time64.c new file mode 100644 index 0000000000..4d47ee7d79 --- /dev/null +++ b/time/tst-strftime4-time64.c @@ -0,0 +1 @@ +#include "tst-strftime4.c" diff --git a/time/tst-strftime4.c b/time/tst-strftime4.c new file mode 100644 index 0000000000..659716d0fa --- /dev/null +++ b/time/tst-strftime4.c @@ -0,0 +1,52 @@ +/* Test strftime and strptime after 2038-01-19 03:14:07 UTC (bug 30053). + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include + +static int +do_test (void) +{ + TEST_VERIFY_EXIT (setenv ("TZ", "UTC0", 1) == 0); + tzset (); + if (sizeof (time_t) > 4) + { + time_t wrap = (time_t) 2147483648LL; + char buf[80]; + struct tm *tm = gmtime (&wrap); + TEST_VERIFY_EXIT (tm != NULL); + TEST_VERIFY_EXIT (strftime (buf, sizeof buf, "%s", tm) > 0); + puts (buf); + TEST_VERIFY (strcmp (buf, "2147483648") == 0); + + struct tm tm2; + char *p = strptime (buf, "%s", &tm2); + TEST_VERIFY_EXIT (p != NULL && *p == '\0'); + time_t t = mktime (&tm2); + printf ("%lld\n", (long long) t); + TEST_VERIFY (t == wrap); + } + else + FAIL_UNSUPPORTED ("32-bit time_t"); + return 0; +} + +#include