mailing list of musl libc
 help / color / Atom feed
* [musl] [PATCH 1/2] Avoid out-of-bounds read for invalid quoted timezone
@ 2020-02-22 22:01 Samuel Holland
  2020-02-22 22:01 ` [musl] [PATCH 2/2] Fix parsing offsets after long timezone names Samuel Holland
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Holland @ 2020-02-22 22:01 UTC (permalink / raw)
  To: musl; +Cc: Samuel Holland

Parsing the timezone name must stop when reaching the null terminator.
In that case, there is no '>' to skip.
---

This was found while investigating the bug fixed by patch 2.

# env -i TZ="<" date
Sat Feb 22 22:34:06 ate 2020
# env -i TZ="UTC0" date
Sat Feb 22 21:34:09 UTC 2020

---
 src/time/__tz.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/time/__tz.c b/src/time/__tz.c
index 185642e8..a962960e 100644
--- a/src/time/__tz.c
+++ b/src/time/__tz.c
@@ -86,9 +86,9 @@ static void getname(char *d, const char **p)
 	int i;
 	if (**p == '<') {
 		++*p;
-		for (i=0; (*p)[i]!='>' && i<TZNAME_MAX; i++)
+		for (i=0; (*p)[i] && (*p)[i]!='>' && i<TZNAME_MAX; i++)
 			d[i] = (*p)[i];
-		++*p;
+		if ((*p)[i]) ++*p;
 	} else {
 		for (i=0; ((*p)[i]|32)-'a'<26U && i<TZNAME_MAX; i++)
 			d[i] = (*p)[i];
-- 
2.24.1


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

* [musl] [PATCH 2/2] Fix parsing offsets after long timezone names
  2020-02-22 22:01 [musl] [PATCH 1/2] Avoid out-of-bounds read for invalid quoted timezone Samuel Holland
@ 2020-02-22 22:01 ` Samuel Holland
  0 siblings, 0 replies; 2+ messages in thread
From: Samuel Holland @ 2020-02-22 22:01 UTC (permalink / raw)
  To: musl; +Cc: Samuel Holland

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

This was causing a failure in gnulib test-parse-datetime, which tries
to use a timezone of 2000 "X"s followed by "0".

---
 src/time/__tz.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/time/__tz.c b/src/time/__tz.c
index a962960e..49a7371e 100644
--- a/src/time/__tz.c
+++ b/src/time/__tz.c
@@ -86,15 +86,15 @@ static void getname(char *d, const char **p)
 	int i;
 	if (**p == '<') {
 		++*p;
-		for (i=0; (*p)[i] && (*p)[i]!='>' && i<TZNAME_MAX; i++)
-			d[i] = (*p)[i];
+		for (i=0; (*p)[i] && (*p)[i]!='>'; i++)
+			if (i<TZNAME_MAX) d[i] = (*p)[i];
 		if ((*p)[i]) ++*p;
 	} else {
-		for (i=0; ((*p)[i]|32)-'a'<26U && i<TZNAME_MAX; i++)
-			d[i] = (*p)[i];
+		for (i=0; ((*p)[i]|32)-'a'<26U; i++)
+			if (i<TZNAME_MAX) d[i] = (*p)[i];
 	}
 	*p += i;
-	d[i] = 0;
+	d[i<TZNAME_MAX?i:TZNAME_MAX] = 0;
 }
 
 #define VEC(...) ((const unsigned char[]){__VA_ARGS__})
-- 
2.24.1


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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-22 22:01 [musl] [PATCH 1/2] Avoid out-of-bounds read for invalid quoted timezone Samuel Holland
2020-02-22 22:01 ` [musl] [PATCH 2/2] Fix parsing offsets after long timezone names Samuel Holland

mailing list of musl libc

Archives are clonable: git clone --mirror http://inbox.vuxu.org/musl

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git