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 430283858D38 for ; Thu, 26 Jan 2023 13:50:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 430283858D38 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=1674741050; 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=zYJ5+MyWStvmyM/5p+h90cKd7oW2LqhWIT9YYXrLkNw=; b=MHPpYI/C4DJ78QflkektjB2vVWaBXYZ51pSlRhxlCobez8Ioy4yP/nTULMVU/fvWK9ceCU c8955+wtpcXpOIHgIkRRVom2yAUjiipsyMCoo5EX0vFhcnsFCleIeBSPr0yKOOLIKHAiaC B/dq/diXqibz48nsxCQTF5yuj8WQzus= Received: from mimecast-mx02.redhat.com (mx3-rdu2.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-461-Ev4bS4azOr-8HDpK0IXOQA-1; Thu, 26 Jan 2023 08:50:47 -0500 X-MC-Unique: Ev4bS4azOr-8HDpK0IXOQA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 550EE3C31DE9; Thu, 26 Jan 2023 13:50:47 +0000 (UTC) Received: from localhost (unknown [10.33.36.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 199442166B26; Thu, 26 Jan 2023 13:50:46 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add workaround for old tzdata.zi files Date: Thu, 26 Jan 2023 13:50:46 +0000 Message-Id: <20230126135046.1441243-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 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_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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 (Fedora 36 and RHEL 6.10). Pushed to trunk. -- >8 -- The tzdata.zi file in the RHEL 6 tzdata-2018e-3.el6 package (with version "unknown") does not conform to the current rules described in the zic(8) man page. Specifically, a Rule name must not start with the character '+' in the current rules, but the older tzdata.zi file used "+" as the name of rules for the "Europe/Sofia" zone. Add a special case to the logic that detects whether a RULES field refers to a named rule or is an offset from standard time. For a string matching exactly "+" treat it as a named Rule, but for any other string starting with '+' treat it as an offset. libstdc++-v3/ChangeLog: * src/c++20/tzdb.cc (operator>>(istream&, ZoneInfo&)): Allow rules named "+" for compatibility with older tzdata.zi files. --- libstdc++-v3/src/c++20/tzdb.cc | 49 +++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index c945f002ad7..c956e861891 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -1967,6 +1967,22 @@ namespace std::chrono return in; } + // Test whether the RULES field of a Zone line is a valid Rule name. + inline bool + is_rule_name(string_view rules) noexcept + { + // The NAME field of a Rule line must start with a character that is + // neither an ASCII digit nor '-' nor '+'. + if (('0' <= rules[0] && rules[0] <= '9') || rules[0] == '-') + return false; + // However, some older tzdata.zi files (e.g. in tzdata-2018e-3.el6 RPM) + // used "+" as a Rule name, so we need to handle that special case. + if (rules[0] == '+') + return rules.size() == 1; // "+" is a rule name, "+1" is not. + // Everything else is the name of a Rule. + return true; + } + istream& operator>>(istream& in, ZoneInfo& inf) { // STDOFF RULES FORMAT [UNTIL] @@ -1976,25 +1992,28 @@ namespace std::chrono in >> off >> quoted{rules} >> fmt; inf.m_offset = off.time; - if (rules == "-") + if (is_rule_name(rules)) { - // Standard time always applies, no DST. - inf.set_abbrev(fmt); - } - else if (string_view("0123456789-+").find(rules[0]) != string_view::npos) - { - // rules specifies the difference from standard time. - at_time rules_time; - istringstream in2(std::move(rules)); - in2 >> rules_time; - inf.m_save = duration_cast(rules_time.time); - select_std_or_dst_abbrev(fmt, inf.m_save); - inf.set_abbrev(fmt); + // `rules` refers to a named Rule which describes transitions. + inf.set_rules_and_format(rules, fmt); } else { - // rules refers to a named Rule which describes transitions. - inf.set_rules_and_format(rules, fmt); + if (rules == "-") + { + // Standard time always applies, no DST. + } + else + { + // `rules` specifies the difference from standard time, + // e.g., "-2:30" + at_time rules_time; + istringstream in2(std::move(rules)); + in2 >> rules_time; + inf.m_save = duration_cast(rules_time.time); + select_std_or_dst_abbrev(fmt, inf.m_save); + } + inf.set_abbrev(fmt); } // YEAR [MONTH [DAY [TIME]]] -- 2.39.1