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 15CFB3858C53 for ; Tue, 5 Apr 2022 04:04:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15CFB3858C53 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-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTP id bQtDncOhM43SgbaQFnRgKZ; Tue, 05 Apr 2022 04:04:03 +0000 Received: from BWINGLISD.cg.shawcable.net. ([184.64.124.72]) by cmsmtp with ESMTP id baQEnIhvMd7RfbaQFnnahw; Tue, 05 Apr 2022 04:04:03 +0000 X-Authority-Analysis: v=2.4 cv=XrLphHJ9 c=1 sm=1 tr=0 ts=624bbfb3 a=oHm12aVswOWz6TMtn9zYKg==:117 a=oHm12aVswOWz6TMtn9zYKg==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=q0jdSloAlabx9ioLVSsA:9 a=QEXdDO2ut3YA:10 a=gALCQhoubqWXC8tSL1EA:9 a=B2y7HmGcmWMA:10 From: Brian Inglis To: Newlib Subject: [PATCH 2/2] tzset_r.c(_tzset_unlocked_r): POSIX angle bracket <> support Date: Mon, 4 Apr 2022 22:03:58 -0600 Message-Id: <20220405040358.18332-3-Brian.Inglis@SystematicSW.ab.ca> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405040358.18332-1-Brian.Inglis@SystematicSW.ab.ca> References: <20220405040358.18332-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: MS4xfE+ZH+7/MKDhWFQtIBbcE9JNGufzbQP7XmQEeDhhGjM20jlm1By/pcvQkk9lo3KRfVuFoxxYSYjE22/jM/lxh/w35qrJSLGD1ejQ8r+UJE8TqdmkoDYE 4WN+rYr53u+YYPVL6KK23+L/mmBVClF94FCOjWdh3DZ7lPC+gMrGRoGO+fKeZOopNDdKLPze4OTs/cwpGNTcW8wd/6EhkTI1USMXNUAtJlueqCFmGe7BaYPA 2ANn31KqaE8V/uiZ3v1gK7KaSNAaRi+A1uj4tAPAcoQ= 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: Tue, 05 Apr 2022 04:04:05 -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 | 67 +++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 12 deletions(-) --------------2.35.1 Content-Type: text/x-patch; name="0002-tzset_r.c-_tzset_unlocked_r-POSIX-angle-bracket-support.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0002-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..bb64d21b0543 100644 --- a/newlib/libc/time/tzset_r.c +++ b/newlib/libc/time/tzset_r.c @@ -1,16 +1,21 @@ #include <_ansi.h> +#include /* {,_POSIX_}TZNAME_MAX */ #include #include #include #include +#include /* sysconf(_SC_TZNAME_MAX) */ #include #include #include "local.h" #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 +50,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 +90,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--