From patchwork Fri Sep 1 10:55:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 137378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c792:0:b0:3f2:4152:657d with SMTP id b18csp802275vqu; Fri, 1 Sep 2023 03:57:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPX404YFjb3bvQmYoQ9dviGhCLU3WBYKB0b4mRX+x0pgaX9mf9FCzOoWhsC4XPmDK1v4tD X-Received: by 2002:a17:906:845c:b0:9a1:b52a:beee with SMTP id e28-20020a170906845c00b009a1b52abeeemr1535751ejy.64.1693565843639; Fri, 01 Sep 2023 03:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693565843; cv=none; d=google.com; s=arc-20160816; b=bPOOA2gUqSU2SclNTQMQ0JTHYyv5n1Kr11oRxnJTjTQjCQL1teibPO57aCXpPirSAK TzqDsmo/wz4sfL6do2ghW5U0oizdHsTniCv4D7aC/hCemU0wWMYH7efnkXQfY8m1dYnW 53icqOThXQDjge0XwEsoZASyrjD6zq3BZXij4uVaz0iILF0OfOcPPDzQtxGnwKKXHgSI D7aDzLOzMSJkgdok1eiIIeHPZ7GFjeONJiQAlMYNYGeJBKUduk46HyoXI5/oRCqZECHI Ohjk5r+JkQmS1psh0yP89xUjYNxQilGUKFkbb5ji7Fp8c5i3W9qRso/+5FTsesplWh07 0FTw== 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=9pNyx7iwhUK5wAJ1WgHqXcOj5RYlbk56LDhotLtTQFU=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=uVXgYIQPy2lj9OtnyCfKVkuOLE3hV62Yfm/gcIkDpMuba/fTT3UiZfLimbC8JuXkT5 nFj7EtH+FIeJ6b6i7kWdyZieQsSyXVPBEKp9Yfk8MbTs4SYzpLuSKg/5Sh9N3tWYPxLy zs7qekNIIgEk3+L+6DFYqXD4YTA3ttVbG81LbhAS+TbSQ/Cz2/iti6tlwgp1Wrw23ac+ AWglGmlD51Ducf1Xs4Dyn4YPMCzOoJQ0eDsfPGAdF9Fw9m8NCjW5kuxEDU7E48Cm+ZjA /zpUafBFPLwuv82FOklLlMDKgCL/wgEMIFNYVNB1ad3ujQ4qMSs06SMR5r8zycJREbin fc+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="nQnVO/4P"; 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 kg12-20020a17090776ec00b0099cc98af80fsi2480309ejc.552.2023.09.01.03.57.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:57:23 -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="nQnVO/4P"; 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 4596C3839DE3 for ; Fri, 1 Sep 2023 10:56:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4596C3839DE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693565772; bh=9pNyx7iwhUK5wAJ1WgHqXcOj5RYlbk56LDhotLtTQFU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nQnVO/4PGDUEJKv2mceCX1Aepo9QPA6u65XUhBUk1GKyzK84j7svhkW/LtiqBk2a0 tSiyPwtynos0pX05huHCyEi3J4iGF4Jqm1G2GYdpUlfYFwynbyEPA2Hvg3O1KmviOV PuU0UHWbSPLYIf33n7dXpZogn+HoLaD180/xC2o4= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 401DC3857722 for ; Fri, 1 Sep 2023 10:55:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 401DC3857722 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) 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 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=unavailable 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.30 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: 1775832497963241087 X-GMAIL-MSGID: 1775832497963241087 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