From patchwork Wed Jul 19 10:11:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 122520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2332787vqt; Wed, 19 Jul 2023 03:18:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlF5UVYoxfFw1gqYoMyqnfM/YzjfnD2sW/S0qIO3AU1mfs2Mdr4Am/QgkKc1tUIXVPYnDxoJ X-Received: by 2002:a05:6512:311b:b0:4f8:7897:55e6 with SMTP id n27-20020a056512311b00b004f8789755e6mr10586945lfb.45.1689761934525; Wed, 19 Jul 2023 03:18:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689761934; cv=none; d=google.com; s=arc-20160816; b=TePPq+OLWzQwVlpx4IF8m/FekuCvYhjZrDbtKOUbgZ8Epv5m/vDq0bjB9izcGjN0QJ mWTjdA96lGBZNfpzmieSVELfvyFKbIlCLXqNH8VBpX5p1cAZ/bZAIbfMcwLNRm4el25m mEL2dZZSdhvmWESHSjuo7grmrcqmMaXEiXyX1IPLkFAuKx+Iq7+ZPTmsE0K6GEQjNQ15 1PIspU9LPqoudM1IeFLsbcNYx0//tB53bPGEsvyGfMMVbZ6cblxdvfB7Jh4/xXDN9lgX PyKj+a9HMmV2CR2Zm/RNZjE8QBd0QS0Eito0WrS68H+aIRjnzmk8mDVVHZAsgUWR+26e Rxmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=hJ2ZdoiDpfutNrawj30/HT4NGucNHQQCTXCw6Q9q6EE=; fh=sC8lnOfyH6gL5FYlMbZ1VDz6qVPMj/3ViLJWKNUCUgQ=; b=ecSSNPy8knWUkzqV+ErKIXSOY7MkDV72JxpNQp25PofBmUSgaQ6eBeNZF5lnOPiC0C om9CnsYKp27xDxl+BLQcla7R/swwtqOoZp1Jc4RQRkWcesMEFmy5xqtUPUJinEolKkgj uTC7Yy+rU/oION/EQ+Ve71+67Okj0iD8oKgl1syRqLn9QPazOPN5Jcsn0DV1j46dAYGr zJBd3XkKfYhD5aAmhcnVxmJZOYx7I/gaLa52cZYHMOi33v2Q2qMSCHtIQQb+A91gOEUs 9VbjN60KmzN533n/eLJBkjJ/fk2aQPNYlGiaSiUcLNB9bzyFlpw4Ck4jSyLC6QKvMqDg +tjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=k8BMHEu4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r14-20020aa7c14e000000b0051e52d264b6si2865676edp.236.2023.07.19.03.18.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 03:18:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=k8BMHEu4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51DA63870C1E for ; Wed, 19 Jul 2023 10:14:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51DA63870C1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689761653; bh=hJ2ZdoiDpfutNrawj30/HT4NGucNHQQCTXCw6Q9q6EE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=k8BMHEu4GmYCbfj7eb/f6cXfOXUwxLXnBYO1plZo09LWMTviJbDUqCra4QsTAwhEy Ul5hmQbeApWL3IECjCf7jNg/BjO57NuiKJYBsJCu21UepXJtfaKDiGDVpkpIS0U1cc kxZEz3Qam+EJQHi3qFBJPwAS80VEldxiqWuRreKE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B9FB93836E9E for ; Wed, 19 Jul 2023 10:12:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9FB93836E9E Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-4RMHO34rOuG-HoNeL8hAKg-1; Wed, 19 Jul 2023 06:12:53 -0400 X-MC-Unique: 4RMHO34rOuG-HoNeL8hAKg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B52A380450D; Wed, 19 Jul 2023 10:12:53 +0000 (UTC) Received: from localhost (unknown [10.42.28.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21DF040C206F; Wed, 19 Jul 2023 10:12:53 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Check for multiple modifiers in chrono format string [PR110708] Date: Wed, 19 Jul 2023 11:11:50 +0100 Message-ID: <20230719101252.2494924-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771843810473195832 X-GMAIL-MSGID: 1771843810473195832 Tested x86_64-linux. Pushed to trunk. This should be backported to gcc-13 too, but it can wait until 13.3 (it's just an accepts-invalid and unlikely to affect anybody in practice). -- >8 -- The logic for handling modified chrono specs like %Ey was just restarting the loop after each modifier, and not checking whether we'd already seen a modifier. libstdc++-v3/ChangeLog: PR libstdc++/110708 * include/bits/chrono_io.h (__formatter_chrono::_M_parse): Only allow a single modifier. * testsuite/std/time/format.cc: Check multiple modifiers. --- libstdc++-v3/include/bits/chrono_io.h | 5 +++++ libstdc++-v3/testsuite/std/time/format.cc | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index 87caa30b83a..5f06a6d76b4 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -426,6 +426,11 @@ namespace __format break; case 'O': case 'E': + if (__mod) [[unlikely]] + { + __allowed_mods = _Mod_none; + break; + } __mod = __c; continue; default: diff --git a/libstdc++-v3/testsuite/std/time/format.cc b/libstdc++-v3/testsuite/std/time/format.cc index b05e5da1af8..0dc45d58dce 100644 --- a/libstdc++-v3/testsuite/std/time/format.cc +++ b/libstdc++-v3/testsuite/std/time/format.cc @@ -68,6 +68,16 @@ test_bad_format_strings() // modifier not valid for conversion specifier VERIFY( not is_format_string_for("{:%Ea}", t) ); VERIFY( not is_format_string_for("{:%Oa}", t) ); + + // more than one modifier (PR libstdc++/110708) + VERIFY( not is_format_string_for("{:%EEc}", t) ); + VERIFY( not is_format_string_for("{:%EEEc}", t) ); + VERIFY( not is_format_string_for("{:%OOd}", t) ); + VERIFY( not is_format_string_for("{:%OOOd}", t) ); + VERIFY( not is_format_string_for("{:%EEy}", t) ); + VERIFY( not is_format_string_for("{:%OOy}", t) ); + VERIFY( not is_format_string_for("{:%OEy}", t) ); + VERIFY( not is_format_string_for("{:%EOy}", t) ); } template