Module Name:    src
Committed By:   christos
Date:           Wed Oct 15 15:13:45 UTC 2014

Modified Files:
        src/lib/libc/time: localtime.c

Log Message:
PR/49284: Andreas Gustafsson: sysinst segfaults when configuring network
manually. When tzload() fails called from zoneinit(), when trying to set the
local timezone for the first time in tzsetlcl(), we end up with a lclptr
that contains garbage, so settzname() core-dumps.

Thanks Andreas for the analysis!


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/lib/libc/time/localtime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/time/localtime.c
diff -u src/lib/libc/time/localtime.c:1.88 src/lib/libc/time/localtime.c:1.89
--- src/lib/libc/time/localtime.c:1.88	Tue Oct 14 16:35:40 2014
+++ src/lib/libc/time/localtime.c	Wed Oct 15 11:13:45 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: localtime.c,v 1.88 2014/10/14 20:35:40 christos Exp $	*/
+/*	$NetBSD: localtime.c,v 1.89 2014/10/15 15:13:45 christos Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -10,7 +10,7 @@
 #if 0
 static char	elsieid[] = "@(#)localtime.c	8.17";
 #else
-__RCSID("$NetBSD: localtime.c,v 1.88 2014/10/14 20:35:40 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.89 2014/10/15 15:13:45 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -1237,9 +1237,14 @@ tzsetlcl(char const *name)
 	if (0 < lcl)
 		(void)strcpy(lcl_TZname, name);
 
-	if (! lclptr)
-		lclptr = malloc(sizeof *lclptr);
-	zoneinit(lclptr, name);
+	if (! lclptr) {
+		struct state *sp = malloc(sizeof *lclptr);
+		if (!zoneinit(sp, name)) {
+			free(sp);
+			return;
+		}
+		lclptr = sp;
+	}
 	settzname();
 	lcl_is_set = lcl;
 }

Reply via email to