From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta002.cacentral1.a.cloudfilter.net (omta002.cacentral1.a.cloudfilter.net [3.97.99.33]) by sourceware.org (Postfix) with ESMTPS id 308733858C39 for ; Fri, 25 Feb 2022 16:40:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 308733858C39 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-4002a.ext.cloudfilter.net ([10.228.9.250]) by cmsmtp with ESMTP id NZkZnbI7SgTZYNddUnvWvn; Fri, 25 Feb 2022 16:40:04 +0000 Received: from BWINGLISD.shawcable.net. ([184.64.124.72]) by cmsmtp with ESMTP id NddTnjEC9qyysNddUnJ0Kj; Fri, 25 Feb 2022 16:40:04 +0000 X-Authority-Analysis: v=2.4 cv=Y6brDzSN c=1 sm=1 tr=0 ts=62190664 a=oHm12aVswOWz6TMtn9zYKg==:117 a=oHm12aVswOWz6TMtn9zYKg==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=jf9T2ZxHsRBIPqn3sicA:9 a=QEXdDO2ut3YA:10 a=gALCQhoubqWXC8tSL1EA:9 a=B2y7HmGcmWMA:10 From: Brian Inglis To: newlib@sourceware.org Subject: [PATCH 2/2] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): POSIX angle bracket <> support Date: Fri, 25 Feb 2022 09:39:59 -0700 Message-Id: <20220225163959.48753-3-Brian.Inglis@SystematicSW.ab.ca> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220225163959.48753-1-Brian.Inglis@SystematicSW.ab.ca> References: <20220225163959.48753-1-Brian.Inglis@SystematicSW.ab.ca> Reply-To: newlib@sourceware.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.35.1" Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfP3RV91cJh7lM6onPS9ARtETIcAC1710y5flroA4/69zywGLiC0AbrMnX23f5vbLTQQmPac1vzO3Pp5YMiq1BGX/xeQy/UtjOtb9gql4GTdsr+HVONSk qH+IhqBGANaB7mm0ym7lEwh7l6D5BFg/TBD7DhafD83Tdeupb6Lo524+NljuXPZkreC/IGLByX5VTZH+98dENMJKu2fBqOehjWT5/F/ZFANYBgvMrPB6Pi2c v4KhNR3JXaH30ffo7CLIBRJsYoMRq7cgndUxFgF84Io= X-Spam-Status: No, score=-1159.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNWANTED_LANGUAGE_BODY 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: Fri, 25 Feb 2022 16:40:07 -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 define POSIX specified minimum TZ abbr size 3 TZNAME_MIN use limits.h TZNAME_MAX, _POSIX_TZNAME_MAX, unistd.h sysconf(_SC_TZNAME_MAX) issue error if no symbols defined (document fallback value in case required) allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g. allow POSIX unquoted alphabetic tz abbr e.g. MESZ apply same changes for DST tz abbr --- newlib/libc/time/tzset_r.c | 74 ++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 10 deletions(-) --------------2.35.1 Content-Type: text/x-patch; name="0002-newlib-libc-time-tzset_r.c-_tzset_unlocked_r-POSIX-a.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0002-newlib-libc-time-tzset_r.c-_tzset_unlocked_r-POSIX-a.patch" diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c index 9e0cf834bd6b..6a5fd578c0be 100644 --- a/newlib/libc/time/tzset_r.c +++ b/newlib/libc/time/tzset_r.c @@ -1,14 +1,30 @@ #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. */ +#define TZNAME_MIN 3 /* POSIX specified minimum TZ abbr size */ +/* TZNAME_MAX - POSIX specified maximum TZ abbr size */ +/* define TZNAME_MAX if undefined and available */ +#if !defined(TZNAME_MAX) +#if defined(_POSIX_TZNAME_MAX) +#define TZNAME_MAX _POSIX_TZNAME_MAX /* use POSIX value */ +#elif defined(_SC_TZNAME_MAX) +#define TZNAME_MAX sysconf(_SC_TZNAME_MAX) /* use sysconf value */ +#else +#error "None of TZNAME_MAX, _POSIX_TZNAME_MAX, _SC_TZNAME_MAX are defined" +#define TZNAME_MAX 9 /* could use fallback value */ +#endif /* defined _POSIX_TZNAME_MAX || _SC_TZNAME_MAX */ +#endif /* !defined(TZNAME_MAX) */ + static char __tzname_std[11]; static char __tzname_dst[11]; static char *prev_tzenv = NULL; @@ -45,8 +61,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 +101,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--