From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by sourceware.org (Postfix) with ESMTPS id 66E5738582AC for ; Tue, 18 Jul 2023 17:17:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66E5738582AC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1b8eb69d641so4441860fac.0 for ; Tue, 18 Jul 2023 10:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689700662; x=1692292662; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qep6dnxVotzUGl47jQzq56q9pewmln0WqFxxS2cjIJQ=; b=WZJ2P7sGbJCGW4d6eeeLmuCPBY62iV+RYY1HPc4ozAcuBsmekTttZZh4ZgP4YO6Tmo qyFx8Q2RYJjGU7Ot2WShxAQC/+faj9HAzD8FwvFg5Zm/mfurJk6rI/JGDVPkts38ukvs K2mQ4QCPL5hu9OLdh4KNURG9LrXSIkabhWfUutxSvUhg9MkzOZpr/wcVr2lx1nIJtVp5 q+acZScHo6hxJOQXel4q57HLhsrRkF3S9USfDfAlKaLRaZg/N0j8Rs29CPwEQCocqO29 0R1MPCR39QVuEySS17qEM2v1fI36wu3QrFk7uRMNz6qM9Ewhl6jcyuTAWjGGANle4iCw G3nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689700662; x=1692292662; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qep6dnxVotzUGl47jQzq56q9pewmln0WqFxxS2cjIJQ=; b=IkbW60lsBRPkqYhgAFIUW8X2JIVdKVY+6QURWu8DLNL7RzE9US4A7RE9957rpHIw6i L1aIoOyQNnUKBl5Z90chta8Hv9WIBeDIiCxCdJH7ijfSl2A+RTZmG2rwI+SCoxuXiAhJ gztElfUABF3SSzN3ja0Ar1T95CYryJ33nTouMWzC0sWKSBfgcT20wX+cKrSFaLNa7L8w OmDdUXWIk8zOjJD1lX7waPpWaj2pn1679iO33Sv6YqgQiM681xkOB5FPiOParKUjXIKX ZcYk/yolUr5tnJizv4o9/KynXQ46wRUdHcln++6nuDd8BC3f1lNB+JxRsx5pU5MkgkWm L6ZQ== X-Gm-Message-State: ABy/qLbCEFRrRuZy9V6tq5QShsZsuDm10m9/66mdSgsdk/9srCGIXXVZ KtjQcKs5PwD4fQ2BcjZBCGsbPXIpi4lILawsqOWzWNTyAiE= X-Google-Smtp-Source: APBJJlFj6xE9yg3j+PM6Rz5A1p2xl3b6zpNQgF5I/WkTmWnXl3nis8yEVNFjkhV9SgRjyfCG7uuoCd2AoEZ2QbMnknY= X-Received: by 2002:a05:6870:e301:b0:1b0:4219:6b5b with SMTP id z1-20020a056870e30100b001b042196b5bmr17535373oad.40.1689700662108; Tue, 18 Jul 2023 10:17:42 -0700 (PDT) MIME-Version: 1.0 References: <20230714145224.1456633-1-lancasterharp@gmail.com> In-Reply-To: From: Stanley Lancaster Date: Tue, 18 Jul 2023 12:17:30 -0500 Message-ID: Subject: Re: Fix %Z parsing in strptime [BZ #16088] To: Paul Eggert Cc: libc-alpha@sourceware.org Content-Type: multipart/alternative; boundary="000000000000bde57b0600c61798" X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: --000000000000bde57b0600c61798 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable --- time/strptime_l.c | 16 +++++++++++----- time/tst-strptime.c | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/time/strptime_l.c b/time/strptime_l.c index 85c3249fcc..2382defc92 100644 --- a/time/strptime_l.c +++ b/time/strptime_l.c @@ -770,11 +770,17 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tmp, break; case 'Z': /* Read timezone but perform no conversion. */ - while (ISSPACE (*rp)) - rp++; - while (!ISSPACE (*rp) && *rp !=3D '\0') - rp++; - break; + { + while (ISSPACE (*rp)) + rp++; + /* Read time zone but perform no conversion. Recognize the format [-+a-zA-Z0-9]{3,}. */ + const char* start_rp =3D rp; + while ((*rp >=3D 'A' && *rp <=3D 'Z') || (*rp >=3D 'a' && *rp <=3D 'z') |= | (*rp >=3D '0' && *rp <=3D '9')) + rp++; + if (start_rp+3 < rp) + return NULL; + } case 'z': /* We recognize four formats: 1. Two digits specify hours. diff --git a/time/tst-strptime.c b/time/tst-strptime.c index 3dae9e0594..40145cb109 100644 --- a/time/tst-strptime.c +++ b/time/tst-strptime.c @@ -48,6 +48,8 @@ static const struct 6, 0, 0, 1 }, { "en_US.ISO-8859-1", "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p", 6, 0, 0, 1 }, + { "en_US.ISO-8859-1", "2000-01-01 08:12:21 AM CST/", "%Y-%m-%d %I:%M:%S %p %Z/", + 6, 0, 0, 1}, { "ja_JP.EUC-JP", "2001 20 \xb7\xee", "%Y %U %a", 1, 140, 4, 21 }, { "ja_JP.EUC-JP", "2001 21 \xb7\xee", "%Y %W %a", 1, 140, 4, 21 }, /* Most of the languages do not need the declension of the month names --=20 2.39.3 On Fri, Jul 14, 2023 at 11:11=E2=80=AFAM Paul Eggert w= rote: > On 2023-07-14 07:52, Stanley Lancaster via Libc-alpha wrote: > > > /* Read timezone but perform no conversion. */ > > + /* we recognize the format [-+a-zA-Z0-9]{3,} */ > > Use GNU style in comment with active voice sentences and two spaces > after sentence end, e.g., "/* Read time zone but perform no conversion. > Recognize the format [-+a-zA-Z0-9]{3,}. */". > > > > + const char* stop_rp =3D rp + 3; > > Again, GNU style: "char *stop_rp" not "char* stop_rp". > > More important, this has undefined behavior if rp + 3 overflows. > Instead, count the number of bytes after the loop finishes, and make > sure it's 3 or more. > > > > + while (((*rp >=3D 'A' && *rp <=3D 'Z') || (*rp >=3D 'a' && *rp = <=3D 'z') > || (*rp >=3D '0' && *rp <=3D '9')) && (rp < stop_rp) && *rp !=3D '\0') > > Omit "&& *rp !=3D '\0'"; it's redundant. Reindent to 80 columns. > > > > + { "C", "1999CST0502123412", "%Y%Z%m%d%H%M%S", 0, 121, 4, 2 }, > > I don't see how this test passes. "CST0502123412" is treated as a time > zone abbreviation, so the only info is the year. Did you run the tests? > If so, why did this test pass? If not, please run. > > Since the patch does not fix BZ#16088, it needs a commit message that > describes what the patch does and why it's a win even though it doesn't > fix. In particular, the patch does not set tm_zone, and there's a reason > for that, and this should be explained. > --000000000000bde57b0600c61798--