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.129.124]) by sourceware.org (Postfix) with ESMTPS id 8890B385828E for ; Fri, 1 Sep 2023 10:55:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8890B385828E 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=1693565722; 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=9pNyx7iwhUK5wAJ1WgHqXcOj5RYlbk56LDhotLtTQFU=; b=EFjUiAi1o7Kgt8OGBBbx9ucxBN3+JnXsZcAM94Pk38H90cp09fa4s8r5wG7LtW6v2e69fc M9srYIg9xWtcURCG5BRbX3cUs+S97b2u4gWJEkGZuADZbRfTLdoypPyrqXNnYIGQUDItm4 7i1eQPRxzvz4270s+vjHG4WDi41WmOI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [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-201-ej1u0M5POFOXCcUMqP_2Gg-1; Fri, 01 Sep 2023 06:55:21 -0400 X-MC-Unique: ej1u0M5POFOXCcUMqP_2Gg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A76D61C18AE3; Fri, 1 Sep 2023 10:55:20 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C1191402C0A; Fri, 1 Sep 2023 10:55:20 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Do not allow chrono::parse to overflow for %C [PR111162] Date: Fri, 1 Sep 2023 11:55:15 +0100 Message-ID: <20230901105519.226612-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 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,URIBL_BLACK 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: Tested x86_64-linux. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: PR libstdc++/111162 * include/bits/chrono_io.h (_Parser::Operator()): Check %C values are in range of year::min() to year::max(). * testsuite/std/time/parse.cc: Check out of range centuries. --- libstdc++-v3/include/bits/chrono_io.h | 9 ++++++++- libstdc++-v3/testsuite/std/time/parse.cc | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index d558802e7d8..f359571b4db 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -3171,7 +3171,14 @@ namespace __detail { auto __v = __read_signed(__num ? __num : 2); if (!__is_failed(__err)) - __century = __v * 100; + { + int __cmin = (int)year::min() / 100; + int __cmax = (int)year::max() / 100; + if (__cmin <= __v && __v <= __cmax) + __century = __v * 100; + else + __century = -2; // This prevents guessing century. + } } else if (__mod == 'E') { diff --git a/libstdc++-v3/testsuite/std/time/parse.cc b/libstdc++-v3/testsuite/std/time/parse.cc index 9b36c5d7db4..46eb7f28c85 100644 --- a/libstdc++-v3/testsuite/std/time/parse.cc +++ b/libstdc++-v3/testsuite/std/time/parse.cc @@ -251,6 +251,18 @@ test_errors() is >> parse("%H:%M %3y", y); // 61min is out of range but not needed VERIFY( is.eof() && ! is.fail() ); VERIFY( y == 2010y ); + + is.clear(); + is.str("328 00"); + is >> parse("%3C %y", y); // 328 is out of range for %C (PR libstdc++/111162) + VERIFY( is.fail() ); + VERIFY( y == 2010y ); + + is.clear(); + is.str("-328 00"); + is >> parse("%3C %y", y); // -328 is out of range for %C + VERIFY( is.fail() ); + VERIFY( y == 2010y ); } void -- 2.41.0