public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Fix %Z parsing in strptime [BZ #16088]
@ 2023-07-14 14:52 Stanley Lancaster
  2023-07-14 16:11 ` Paul Eggert
  0 siblings, 1 reply; 9+ messages in thread
From: Stanley Lancaster @ 2023-07-14 14:52 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stanley Lancaster

---
 time/strptime_l.c   | 5 ++++-
 time/tst-strptime.c | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/time/strptime_l.c b/time/strptime_l.c
index 85c3249fcc..5954015c4e 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -770,9 +770,12 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tmp,
 	  break;
 	case 'Z':
 	  /* Read timezone but perform no conversion.  */
+	  /* we recognize the format [-+a-zA-Z0-9]{3,} */
 	  while (ISSPACE (*rp))
 	    rp++;
-	  while (!ISSPACE (*rp) && *rp != '\0')
+	  
+	  const char* stop_rp = rp + 3;
+	  while (((*rp >= 'A' && *rp <= 'Z') || (*rp >= 'a' && *rp <= 'z') || (*rp >= '0' && *rp <= '9')) && (rp < stop_rp) && *rp != '\0')
 	    rp++;
 	  break;
 	case 'z':
diff --git a/time/tst-strptime.c b/time/tst-strptime.c
index 3dae9e0594..31d6945ef1 100644
--- a/time/tst-strptime.c
+++ b/time/tst-strptime.c
@@ -38,6 +38,7 @@ static const struct
   { "C", "03/03/00", "%D", 5, 62, 2, 3 },
   { "C", "9/9/99", "%x", 4, 251, 8, 9 },
   { "C", "19990502123412", "%Y%m%d%H%M%S", 0, 121, 4, 2 },
+  { "C", "1999CST0502123412", "%Y%Z%m%d%H%M%S", 0, 121, 4, 2 },
   { "C", "2001 20 Mon", "%Y %U %a", 1, 140, 4, 21 },
   { "C", "2001 21 Mon", "%Y %W %a", 1, 140, 4, 21 },
   { "C", "2001 21 Mon", "%2000Y %W %a", 1, 140, 4, 21 },
-- 
2.39.3


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Fix %Z parsing in strptime [BZ #16088]
@ 2023-07-17 12:57 Wilco Dijkstra
  2023-07-17 17:19 ` Paul Eggert
  0 siblings, 1 reply; 9+ messages in thread
From: Wilco Dijkstra @ 2023-07-17 12:57 UTC (permalink / raw)
  To: lancasterharp; +Cc: 'GNU C Library'

Hi Stanley,

> +	  /* we recognize the format [-+a-zA-Z0-9]{3,} */

Is that really the correct format? Eg. should it be able to parse UTC offsets like UTC+04:30?

> 	  while (ISSPACE (*rp))
> 	    rp++;
>-	  while (!ISSPACE (*rp) && *rp != '\0')
>+	  
>+	  const char* stop_rp = rp + 3;
>+	  while (((*rp >= 'A' && *rp <= 'Z') || (*rp >= 'a' && *rp <= 'z') || (*rp >= '0' && *rp <= '9')) && (rp < stop_rp) && *rp != '\0')

This is basically isalnum() but not allowing '+' or '-'. And if timezone offsets are allowed,
we'd also need ':'. And rather than allowing any sequence of these characters, would it
not be better to scan just for isalpha() first, and only if you see '+' or '-' check the UTC
offset syntax?

Cheers,
Wilco

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-24 16:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14 14:52 Fix %Z parsing in strptime [BZ #16088] Stanley Lancaster
2023-07-14 16:11 ` Paul Eggert
2023-07-18 17:17   ` Stanley Lancaster
2023-07-18 17:22     ` Stanley Lancaster
2023-07-19  2:13     ` Paul Eggert
2023-07-24 13:53       ` [PATCH] Update to %Z fix Stanley Lancaster
2023-07-24 16:48         ` Paul Eggert
2023-07-17 12:57 Fix %Z parsing in strptime [BZ #16088] Wilco Dijkstra
2023-07-17 17:19 ` Paul Eggert

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).