From: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
To: Newlib <newlib@sourceware.org>
Subject: [PATCH 2/2] tzset_r.c(_tzset_unlocked_r): POSIX angle bracket <> support
Date: Mon, 4 Apr 2022 22:03:58 -0600 [thread overview]
Message-ID: <20220405040358.18332-3-Brian.Inglis@SystematicSW.ab.ca> (raw)
In-Reply-To: <20220405040358.18332-1-Brian.Inglis@SystematicSW.ab.ca>
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
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. <MESZ+0330>
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(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-tzset_r.c-_tzset_unlocked_r-POSIX-angle-bracket-support.patch --]
[-- Type: text/x-patch; name="0002-tzset_r.c-_tzset_unlocked_r-POSIX-angle-bracket-support.patch", Size: 3041 bytes --]
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 <limits.h> /* {,_POSIX_}TZNAME_MAX */
#include <reent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h> /* sysconf(_SC_TZNAME_MAX) */
#include <sys/types.h>
#include <sys/time.h>
#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. <MESZ+0330> */
+ 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. <MESZ+0330> */
+ 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 */
next prev parent reply other threads:[~2022-04-05 4:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-05 4:03 [PATCH 0/2] add tzset/_r POSIX angle bracket <> support in TZ env var Brian Inglis
2022-04-05 4:03 ` [PATCH 1/2] tzset.c: doc update POSIX angle bracket <> support Brian Inglis
2022-04-05 4:03 ` Brian Inglis [this message]
2022-04-07 9:56 ` [PATCH 2/2] tzset_r.c(_tzset_unlocked_r): " jdoubleu
2022-04-07 16:07 ` Brian Inglis
2022-04-07 16:18 ` jdoubleu
2022-04-07 15:48 ` jdoubleu
2022-04-07 21:35 ` Jeff Johnston
2022-04-07 23:36 ` Brian Inglis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220405040358.18332-3-Brian.Inglis@SystematicSW.ab.ca \
--to=brian.inglis@systematicsw.ab.ca \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).