Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/eeprom PR/47528: Izumi Tsutsui: eeprom(8) dumps cor...



details:   https://anonhg.NetBSD.org/src/rev/a11a5eb01eae
branches:  trunk
changeset: 784610:a11a5eb01eae
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 03 15:30:04 2013 +0000

description:
PR/47528: Izumi Tsutsui: eeprom(8) dumps core after 64 bit time_t changes

diffstat:

 usr.sbin/eeprom/eehandlers.c |  22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diffs (57 lines):

diff -r 49b014ffaa46 -r a11a5eb01eae usr.sbin/eeprom/eehandlers.c
--- a/usr.sbin/eeprom/eehandlers.c      Sun Feb 03 14:51:57 2013 +0000
+++ b/usr.sbin/eeprom/eehandlers.c      Sun Feb 03 15:30:04 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eehandlers.c,v 1.15 2009/04/30 07:45:28 nakayama Exp $ */
+/*     $NetBSD: eehandlers.c,v 1.16 2013/02/03 15:30:04 christos Exp $ */
 
 /*-
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -40,6 +40,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <util.h>
+#include <sys/inttypes.h>
 
 #include <machine/eeprom.h>
 #ifdef __sparc__
@@ -140,6 +141,7 @@
        struct keytabent *ktent;
        char *arg;
 {
+       uint32_t hwtime;
        time_t t;
        char *cp, *cp2;
 
@@ -154,18 +156,26 @@
                } else
                        if ((t = parsedate(arg, NULL, NULL)) == (time_t)(-1))
                                BARF(ktent);
+               hwtime = (uint32_t)t;   /* XXX 32 bit time_t on hardware */
+               if (hwtime != t)
+                       warnx("time overflow");
 
-               if (doio(ktent, (u_char *)&t, sizeof(t), IO_WRITE))
+               if (doio(ktent, (u_char *)&hwtime, sizeof(hwtime), IO_WRITE))
                        FAILEDWRITE(ktent);
-       } else
-               if (doio(ktent, (u_char *)&t, sizeof(t), IO_READ))
+       } else {
+               if (doio(ktent, (u_char *)&hwtime, sizeof(hwtime), IO_READ))
                        FAILEDREAD(ktent);
+               t = (time_t)hwtime;     /* XXX 32 bit time_t on hardware */
+       }
 
        cp = ctime(&t);
-       if ((cp2 = strrchr(cp, '\n')) != NULL)
+       if (cp != NULL && (cp2 = strrchr(cp, '\n')) != NULL)
                *cp2 = '\0';
 
-       printf("%s=%ld (%s)\n", ktent->kt_keyword, (long)t, cp);
+       printf("%s=%" PRId64, ktent->kt_keyword, (int64_t)t);
+       if (cp != NULL)
+               printf(" (%s)", cp);
+       printf("\n");
 }
 
 void



Home | Main Index | Thread Index | Old Index