Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/time Fix a bug reported by Gene, and debugged by Ro...



details:   https://anonhg.NetBSD.org/src/rev/5d17be3938ca
branches:  trunk
changeset: 752165:5d17be3938ca
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 17 17:25:55 2010 +0000

description:
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!)

diffstat:

 lib/libc/time/localtime.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (61 lines):

diff -r 36cb59594f24 -r 5d17be3938ca lib/libc/time/localtime.c
--- a/lib/libc/time/localtime.c Wed Feb 17 16:15:15 2010 +0000
+++ b/lib/libc/time/localtime.c Wed Feb 17 17:25:55 2010 +0000
@@ -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 */



Home | Main Index | Thread Index | Old Index