[1/2] Avoid out-of-bounds read for invalid quoted timezone

Submitted by Samuel Holland on Feb. 22, 2020, 10:01 p.m.

Details

Message ID 20200222220113.55710-1-samuel@sholland.org
State New
Series "Series without cover letter"
Headers show

Commit Message

Samuel Holland Feb. 22, 2020, 10:01 p.m.
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(-)

Patch hide | download patch | download mbox

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];