git: 9front

Download patch

ref: 7997d7475aab6dbe8cbddfeaa7ca54150064b3b4
parent: 314b8fc5f6be7276cc89def58eecdf92ab070b37
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Aug 24 10:47:10 EDT 2020

tm2sec: clear new fields in tm

Old users of the time APIs would hand-craft
time structs without first zeroing all the
members. When this got into tmnorm(), we
would try to access the new members, and
things would go off the rails.

This makes tm2sec() clear the new fields
before passing them to the new APIs, so
that the hand-crafted structs remain
valid.

--- a/sys/src/libc/9sys/tm2sec.c
+++ b/sys/src/libc/9sys/tm2sec.c
@@ -7,5 +7,14 @@
 	Tm tt;
 
 	tt = *tm;
+	/*
+	 * The zone offset should be calculated,
+	 * but old code may not init tz member.
+	 * nil it out so we don't access junk.
+	 * while we're at it, old code probably
+	 * leaves junk in nsec.
+	 */
+	tt.nsec = 0;
+	tt.tz = nil;
 	return tmnorm(&tt);
 }
--