shithub: riscv

Download patch

ref: b1a13414cd5c9cc8682a66885fb0acd8654c90de
parent: 0505f8fb3a88e952709aaead1e13971b6e8514f3
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);
 }