From 8af39e37e03b661f58fa2abc2479d93f2d2821c2 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Thu, 12 Nov 2020 07:40:53 -0800 Subject: [PATCH] Ensure new timezone names end in '>' Reduce code slightly and ensure that only names of the form '<...>' including the terminal '>' are accepted in the parser. Fixes a potential error handling corner case. --- newlib/libc/time/tzset_r.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c index 9faefc879..03782e9fd 100644 --- a/newlib/libc/time/tzset_r.c +++ b/newlib/libc/time/tzset_r.c @@ -56,14 +56,13 @@ _DEFUN (_tzset_r, (reent_ptr), if (tzenv[0] == '<') { /* This is of the form "<[+-]nn>" so needs a different parsing */ - if (sscanf (tzenv, "%9[^>]%n", __tzname_std, &n) <= 0) + if (sscanf (tzenv, "%9[^>]>%n", __tzname_std, &n) <= 0) { TZ_UNLOCK; return; } - /* Include the final > and skip it */ + /* Include the final > */ strcat (__tzname_std, ">"); - n++; } else { @@ -101,7 +100,7 @@ _DEFUN (_tzset_r, (reent_ptr), if (tzenv[0] == '<') { /* This is of the form "<[+-]nn>" so needs a different parsing */ - if (sscanf (tzenv, "%9[^>]%n", __tzname_dst, &n) <= 0) + if (sscanf (tzenv, "%9[^>]>%n", __tzname_dst, &n) <= 0) { /* No dst */ _tzname[1] = _tzname[0]; _timezone = tz->__tzrule[0].offset; @@ -109,9 +108,8 @@ _DEFUN (_tzset_r, (reent_ptr), TZ_UNLOCK; return; } - /* Include the final > and skip it */ + /* Include the final > */ strcat (__tzname_dst, ">"); - n++; _tzname[1] = __tzname_dst; } else