Module Name:    src
Committed By:   christos
Date:           Wed Feb 17 17:25:55 UTC 2010

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

Log Message:
Fix a bug reported by Gene, and debugged by Robert Elz. fsck_ffs can coredump
if the timezone file fails to load, due to late initialization of sp->goahead
to false in tzload, causing localsub to return NULL in the "cannot happen"
case. The fix is belt and suspenders:
        - initialize sp->goback and sp->goahead very early in tzload
        - replace all malloc calls with callocs, and remove the bogus
          casts (it is not the 70's anymore!)


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 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.46 src/lib/libc/time/localtime.c:1.47
--- src/lib/libc/time/localtime.c:1.46	Tue Feb  2 14:04:37 2010
+++ src/lib/libc/time/localtime.c	Wed Feb 17 12:25:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: localtime.c,v 1.46 2010/02/02 19:04:37 christos Exp $	*/
+/*	$NetBSD: localtime.c,v 1.47 2010/02/17 17:25:55 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.9";
 #else
-__RCSID("$NetBSD: localtime.c,v 1.46 2010/02/02 19:04:37 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.47 2010/02/17 17:25:55 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -386,6 +386,7 @@
 					4 * TZ_MAX_TIMES];
 	} u;
 
+	sp->goback = sp->goahead = FALSE;
 	if (name == NULL && (name = TZDEFAULT) == NULL)
 		return -1;
 	{
@@ -600,7 +601,6 @@
 					sp->ttis[sp->typecnt++] = ts.ttis[1];
 			}
 	}
-	sp->goback = sp->goahead = FALSE;
 	if (sp->timecnt > 1) {
 		for (i = 1; i < sp->timecnt; ++i)
 			if (typesequiv(sp, sp->types[i], sp->types[0]) &&
@@ -1208,7 +1208,7 @@
 #ifdef ALL_STATE
 	if (lclptr == NULL) {
 		int saveerrno = errno;
-		lclptr = (struct state *) malloc(sizeof *lclptr);
+		lclptr = calloc(1, sizeof *lclptr);
 		errno = saveerrno;
 		if (lclptr == NULL) {
 			settzname();	/* all we can do */
@@ -1266,7 +1266,7 @@
 #ifdef ALL_STATE
 	if (lclptr == NULL) {
 		saveerrno = errno;
-		lclptr = (struct state *) malloc(sizeof *lclptr);
+		lclptr = calloc(1, sizeof *lclptr);
 		errno = saveerrno;
 		if (lclptr == NULL) {
 			settzname();	/* all we can do */
@@ -1459,7 +1459,7 @@
 		gmt_is_set = TRUE;
 #ifdef ALL_STATE
 		saveerrno = errno;
-		gmtptr = (struct state *) malloc(sizeof *gmtptr);
+		gmtptr = calloc(1, sizeof *gmtptr);
 		errno = saveerrno;
 		if (gmtptr != NULL)
 #endif /* defined ALL_STATE */

Reply via email to