From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta001.cacentral1.a.cloudfilter.net (omta001.cacentral1.a.cloudfilter.net [3.97.99.32]) by sourceware.org (Postfix) with ESMTPS id E4518385840F for ; Thu, 7 Apr 2022 23:34:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4518385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=SystematicSW.ab.ca Authentication-Results: sourceware.org; spf=none smtp.mailfrom=systematicsw.ab.ca Received: from shw-obgw-4003a.ext.cloudfilter.net ([10.228.9.183]) by cmsmtp with ESMTP id cSvHnfONV43Sgcbe4nd2UC; Thu, 07 Apr 2022 23:34:32 +0000 Received: from BWINGLISD.cg.shawcable.net. ([184.64.124.72]) by cmsmtp with ESMTP id cbe3n6Nx0QV6mcbe4nyHmw; Thu, 07 Apr 2022 23:34:32 +0000 X-Authority-Analysis: v=2.4 cv=PbTsOwtd c=1 sm=1 tr=0 ts=624f7508 a=oHm12aVswOWz6TMtn9zYKg==:117 a=oHm12aVswOWz6TMtn9zYKg==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=q0jdSloAlabx9ioLVSsA:9 a=QEXdDO2ut3YA:10 a=Bwab9PuflVqNbyYkQaIA:9 a=B2y7HmGcmWMA:10 From: Brian Inglis To: Newlib Subject: [PATCH v2 2/2] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): POSIX angle bracket <> support Date: Thu, 7 Apr 2022 17:34:25 -0600 Message-Id: <20220407233425.2012-3-Brian.Inglis@SystematicSW.ab.ca> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407233425.2012-1-Brian.Inglis@SystematicSW.ab.ca> References: <20220407233425.2012-1-Brian.Inglis@SystematicSW.ab.ca> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.35.1" Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfOk8lC8gZRtlYIWKtNPp0Lmqh1JC3y30RDnkifQqBgd1nLzfe0C+q0Qc0PzB3oCfximLujkqhQmP/OzMuCQxaPSwkuOG4kK9CKoDih+rFnItNEJMMYeg p4kQm44B+2tAmpKlAj0Mlr6fW3s7lMutdCKKJ9nAPhWOK/RrwgOVtFC08aum8+zAYMp3+8hpAkHYPabx7WOC4qPdOChPZfTzIXztm9RsePRwit+loUrgBPQZ wGh3Y7F1HD1QCf0HNrJuO/Ea6/X3o+B5SjaeAhS7lHg= X-Spam-Status: No, score=-1170.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2022 23:34:34 -0000 This is a multi-part message in MIME format. --------------2.35.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit local defines for POSIX minimum TZ abbr size 3 TZNAME_MIN and maximum TZ abbr size supported 10 TZNAME_MAX allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g. allow POSIX unquoted alphabetic tz abbr e.g. MESZ allow same suuport for DST tz abbr --- newlib/libc/time/tzset_r.c | 65 +++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 12 deletions(-) --------------2.35.1 Content-Type: text/x-patch; name="0002-newlib-libc-time-tzset_r.c-_tzset_unlocked_r-POSIX-angle-bracket-support.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0002-newlib-libc-time-tzset_r.c-_tzset_unlocked_r-POSIX-angle-bracket-support.patch" diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c index 9e0cf834bd6b..9cb30b188f98 100644 --- a/newlib/libc/time/tzset_r.c +++ b/newlib/libc/time/tzset_r.c @@ -9,8 +9,11 @@ #define sscanf siscanf /* avoid to pull in FP functions. */ -static char __tzname_std[11]; -static char __tzname_dst[11]; +#define TZNAME_MIN 3 /* POSIX min TZ abbr size local def */ +#define TZNAME_MAX 10 /* POSIX max TZ abbr size local def */ + +static char __tzname_std[TZNAME_MAX + 1]; +static char __tzname_dst[TZNAME_MAX + 1]; static char *prev_tzenv = NULL; void @@ -45,8 +48,25 @@ _tzset_unlocked_r (struct _reent *reent_ptr) if (*tzenv == ':') ++tzenv; - if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0) - return; + /* allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g. */ + if (*tzenv == '<') + { + ++tzenv; + + /* quit if no items, too few or too many chars, or no close quote '>' */ + if (sscanf (tzenv, "%10[-+0-9A-Za-z]%n", __tzname_std, &n) <= 0 + || n < TZNAME_MIN || TZNAME_MAX < n || '>' != tzenv[n]) + return; + + ++tzenv; /* bump for close quote '>' */ + } + else + { + /* allow POSIX unquoted alphabetic tz abbr e.g. MESZ */ + if (sscanf (tzenv, "%10[A-Za-z]%n", __tzname_std, &n) <= 0 + || n < TZNAME_MIN || TZNAME_MAX < n) + return; + } tzenv += n; @@ -68,17 +88,38 @@ _tzset_unlocked_r (struct _reent *reent_ptr) tz->__tzrule[0].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh); _tzname[0] = __tzname_std; tzenv += n; - - if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_dst, &n) <= 0) - { /* No dst */ - _tzname[1] = _tzname[0]; - _timezone = tz->__tzrule[0].offset; - _daylight = 0; - return; + + /* allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g. */ + if (*tzenv == '<') + { + ++tzenv; + + /* quit if no items, too few or too many chars, or no close quote '>' */ + if (sscanf (tzenv, "%10[-+0-9A-Za-z]%n", __tzname_dst, &n) <= 0 + || n < TZNAME_MIN || TZNAME_MAX < n || '>' != tzenv[n]) + { /* No dst */ + _tzname[1] = _tzname[0]; + _timezone = tz->__tzrule[0].offset; + _daylight = 0; + return; + } + + ++tzenv; /* bump for close quote '>' */ } else - _tzname[1] = __tzname_dst; + { + /* allow POSIX unquoted alphabetic tz abbr e.g. MESZ */ + if (sscanf (tzenv, "%10[A-Za-z]%n", __tzname_dst, &n) <= 0 + || n < TZNAME_MIN || TZNAME_MAX < n) + { /* No dst */ + _tzname[1] = _tzname[0]; + _timezone = tz->__tzrule[0].offset; + _daylight = 0; + return; + } + } + _tzname[1] = __tzname_dst; tzenv += n; /* otherwise we have a dst name, look for the offset */ --------------2.35.1--