From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 8A698385E020 for ; Wed, 19 Jul 2023 10:12:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A698385E020 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689761576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hJ2ZdoiDpfutNrawj30/HT4NGucNHQQCTXCw6Q9q6EE=; b=bYtI38eJQi1l+zmRNVhlyimGKg+24evTxarutvE2dMwk0tMQnfjRrkzmVN+r/XBoLhJVP8 5ClIrv+5YUbybA/9iafAQwrWU8SPKNmcPMu68BS3tktHjYEStYB5hpO6fCQJA+OY0F6tJW wtiQfoaC3OmQELyPga4fpcnwHPsfk80= 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) From: Jonathan Wakely 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 -- 2.41.0