From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by sourceware.org (Postfix) with ESMTPS id 78B5D385B515 for ; Tue, 7 Feb 2023 14:10:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78B5D385B515 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc34.google.com with SMTP id 123-20020a4a0681000000b004faa9c6f6b9so1413443ooj.11 for ; Tue, 07 Feb 2023 06:10:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Nqs4BorSUtfGYJmj7lzsEL4MhueuJbq6iKHMIQrgUhk=; b=DOaUNVGNkn/0ADiO9tuikv62CGOivgvtaM8lh4HIz7ut/jzvkIfC8sveethFrtAtSO zsiooUWY6vcIdil3Hn9xVoZ9/Y2GjgnoTBRG2Wx0k05qJJ0HpBzLbkC3EtnduF9nQiGK JJrzQme3jxmnlRX62q7C+P0T+GezhpxDUFxxbrPFQyjOMb62ZEJpJ9aPXgzellekGylg mvfSGti9dIYmQWf5CA1ATxED5cnMUwMH0ZK59b4H8n9K7QXd4uz2kPGET9IScTE+d6iE BR1lDI0OwxWH9Ca2uTpUyDkPd6mO8qomd6LLiRlklvP9jWxdbQmbEPRScm+EzH81hAHd pvvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Nqs4BorSUtfGYJmj7lzsEL4MhueuJbq6iKHMIQrgUhk=; b=R6EXls1AmKATECWnk1tcycfSxnGKHR5OyQExAnRB27KxnkKfwlnNh7e9a5wc8LVcy4 MAUSLbCirU9LGkQwGj2ajfM64BDPhKW9FtoeVKUn31uKOpx/xDy/iJen5nRO3fQPX6Mw xUwxRaSsHN9H4fpFxcd2cRy9Oe3GFVAY4niNWQw93Gk5VqJb/0piz9UeeP+qCq4NmHOM aEkMcOZVzGNpbU4A///CtqMFhdlfuJ4hF5EzX41VVPg6k/Vww5cbTLgSPCfKACCY/SQF +wIGb1o265sbmAl1C9O9zCarXDj4y6hIO7nk0f7HNyVcfGcFaVtLxbspoz7k/Jh1WMx5 mQiw== X-Gm-Message-State: AO0yUKV5tVk9346bGaDLoy2oNsYAyfmYyWlL2m8Q+EBX2RVlSJ6YgxGX T0Kz0qzJXMYNGVe3zP0QWNptfpb2xesIAmpTDvI= X-Google-Smtp-Source: AK7set8b9r612uuQ5Anmb3d2iBBISfQUFPdAgHFusFR8H//HxhZxyziZgKWe8X+Z8J07c7SCQ6Hrbg== X-Received: by 2002:a4a:7505:0:b0:4f2:cba3:8929 with SMTP id j5-20020a4a7505000000b004f2cba38929mr976172ooc.6.1675779027021; Tue, 07 Feb 2023 06:10:27 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:8ced:3d04:3626:cc0e:457c]) by smtp.gmail.com with ESMTPSA id w31-20020a4a97a2000000b004c60069d1fbsm6061332ooi.11.2023.02.07.06.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 06:10:26 -0800 (PST) From: Adhemerval Zanella To: libc-stable@sourceware.org Cc: Andreas Schwab Subject: [COMMITTED] Use 64-bit time_t interfaces in strftime and strptime (bug 30053) Date: Tue, 7 Feb 2023 11:10:21 -0300 Message-Id: <20230207141021.3901902-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Andreas Schwab Both functions use time_t only internally, so the ABI is not affected. (cherry picked from commit 41349f6f67c83e7bafe49f985b56493d2c4c9c77) --- NEWS | 1 + 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, 63 insertions(+), 2 deletions(-) create mode 100644 time/tst-strftime4-time64.c create mode 100644 time/tst-strftime4.c diff --git a/NEWS b/NEWS index c5e142eb3a..aff6951c1d 100644 --- a/NEWS +++ b/NEWS @@ -54,6 +54,7 @@ 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 + [30053] time: strftime %s returns -1 after 2038 on 32 bits systems Version 2.36 diff --git a/time/Makefile b/time/Makefile index 470275b90c..2f4aa2d528 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 75554fee7c..4d7c4ea828 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 a3c5681fc2..f927448204 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 -- 2.34.1