mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: musl@lists.openwall.com
Cc: Samuel Holland <samuel@sholland.org>
Subject: [musl] [PATCH 2/2] Fix parsing offsets after long timezone names
Date: Sat, 22 Feb 2020 16:01:13 -0600	[thread overview]
Message-ID: <20200222220113.55710-2-samuel@sholland.org> (raw)
In-Reply-To: <20200222220113.55710-1-samuel@sholland.org>

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


      reply	other threads:[~2020-02-22 22:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200222220113.55710-2-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).