Browse Source

fix parsing offsets after long timezone names

TZ containg a timezone name with >TZNAME_MAX characters currently
breaks musl's timezone parsing. getname() stops after TZNAME_MAX
characters. getoff() will consume no characters (because the next
character is not a digit) and incorrectly return 0. Then, because
there are remaining alphabetic characters, __daylight == 1, and
dst_off == -3600.

getname() must consume the entire timezone name, even if it will not
fit in d/__tzname, so when it returns, s points to the offset digits.
master
Samuel Holland 6 years ago
committed by Rich Felker
parent
commit
33338ebc85
  1. 10
      src/time/__tz.c

10
src/time/__tz.c

@ -86,15 +86,15 @@ static void getname(char *d, const char **p)
int i; int i;
if (**p == '<') { if (**p == '<') {
++*p; ++*p;
for (i=0; (*p)[i] && (*p)[i]!='>' && i<TZNAME_MAX; i++) for (i=0; (*p)[i] && (*p)[i]!='>'; i++)
d[i] = (*p)[i]; if (i<TZNAME_MAX) d[i] = (*p)[i];
if ((*p)[i]) ++*p; if ((*p)[i]) ++*p;
} else { } else {
for (i=0; ((*p)[i]|32)-'a'<26U && i<TZNAME_MAX; i++) for (i=0; ((*p)[i]|32)-'a'<26U; i++)
d[i] = (*p)[i]; if (i<TZNAME_MAX) d[i] = (*p)[i];
} }
*p += i; *p += i;
d[i] = 0; d[i<TZNAME_MAX?i:TZNAME_MAX] = 0;
} }
#define VEC(...) ((const unsigned char[]){__VA_ARGS__}) #define VEC(...) ((const unsigned char[]){__VA_ARGS__})

Loading…
Cancel
Save