[PATCH] Fix %Z parsing in strptime [BZ #16088]
Stanley Lancaster
lancasterharp@gmail.com
Thu Jun 22 15:00:21 GMT 2023
%Z parsing terminated on space, should've terminated on next character in format string
Author: Stanley Lancast <lancasterharp@gmail.com>
---
time/strptime_l.c | 5 +++--
time/tst-strptime.c | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/time/strptime_l.c b/time/strptime_l.c
index 85c3249fcc..5f96795406 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -772,8 +772,9 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tmp,
/* Read timezone but perform no conversion. */
while (ISSPACE (*rp))
rp++;
- while (!ISSPACE (*rp) && *rp != '\0')
- rp++;
+
+ while (*rp != *(fmt) && *rp != '\0')
+ rp++;
break;
case 'z':
/* We recognize four formats:
diff --git a/time/tst-strptime.c b/time/tst-strptime.c
index 3dae9e0594..6eb1af5c15 100644
--- a/time/tst-strptime.c
+++ b/time/tst-strptime.c
@@ -37,6 +37,7 @@ static const struct
{ "C", "2000-01-01", "%Y-%m-%d", 6, 0, 0, 1 },
{ "C", "03/03/00", "%D", 5, 62, 2, 3 },
{ "C", "9/9/99", "%x", 4, 251, 8, 9 },
+ { "C", "CST-2000-01-01", "%Z-%Y-%m-%d", 6, 0, 0, 1}, /* Ensure %Z terminates properly */
{ "C", "19990502123412", "%Y%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 },
--
2.31.1
More information about the Libc-alpha
mailing list