]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Fix blkid's last verification logic to work when the system clock is insane
authorTheodore Ts'o <tytso@mit.edu>
Mon, 13 Mar 2006 04:25:15 +0000 (23:25 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 13 Mar 2006 04:25:15 +0000 (23:25 -0500)
Users have reported problems on newly installed systems when the
Macintosh's system clock battery is dead and the hardware clock is
returning a date of 1904.  Turns out there were some bugs in handling
dates before the Unix epoch.

Addresses Red Hat Bug: #182188

probe.c (blkid_verify): Fix the bid_time sanity checking logic,
so that if last verification time is more recent than the
current time, or the comparison between the last
verification time and the current time causes an overflow,
a device verification will take place.

devname.c (blkid_get_dev): Set the initial bid_time to be
INT_MIN, to guarantee that blkid_verify will always be run
even when the system clock is insane.

dev.c (blkid_debug_dump_dev), read.c (debug_dump_dev),
save.c (save_dev): Fix the printf format for dev->bid_time
to match the fact that it is an signed type.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/blkid/ChangeLog
lib/blkid/dev.c
lib/blkid/devname.c
lib/blkid/probe.c
lib/blkid/read.c
lib/blkid/save.c

index 094f9225282ae20dae6e313bc912dfb70e74d88e..e0dac822b53620a9a549592a88f0c044c42bb71c 100644 (file)
@@ -1,3 +1,19 @@
+2006-03-12  Theodore Ts'o  <tytso@mit.edu>
+
+       * probe.c (blkid_verify): Fix the bid_time sanity checking logic,
+               so that if last verification time is more recent than the
+               current time, or the comparison between the last
+               verification time and the current time causes an overflow,
+               a device verification will take place.
+
+       * devname.c (blkid_get_dev): Set the initial bid_time to be
+               INT_MIN, to guarantee that blkid_verify will always be run
+               even when the system clock is insane.
+
+       * dev.c (blkid_debug_dump_dev), read.c (debug_dump_dev), 
+               save.c (save_dev): Fix the printf format for dev->bid_time
+               to match the fact that it is an signed type.
+
 2006-03-10  Theodore Ts'o  <tytso@mit.edu>
 
        * probe.c (probe_ext3): If the filesystem has an external journal,
index adb855a50107b5fcd3d6aa526c0287235717e836..ea2ccead153870be29bbe35558cfe6d092f3cccd 100644 (file)
@@ -69,7 +69,7 @@ void blkid_debug_dump_dev(blkid_dev dev)
 
        printf("  dev: name = %s\n", dev->bid_name);
        printf("  dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno);
-       printf("  dev: TIME=\"%lu\"\n", dev->bid_time);
+       printf("  dev: TIME=\"%ld\"\n", dev->bid_time);
        printf("  dev: PRI=\"%d\"\n", dev->bid_pri);
        printf("  dev: flags = 0x%08X\n", dev->bid_flags);
 
index 0a13c477d455ea80d52da7062d678139d7698261..b2ff40f0221a16a47dabf6f4f35d08122c707789 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <limits.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -70,6 +71,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
                dev = blkid_new_dev();
                if (!dev)
                        return NULL;
+               dev->bid_time = INT_MIN;
                dev->bid_name = blkid_strdup(devname);
                dev->bid_cache = cache;
                list_add_tail(&dev->bid_devs, &cache->bic_devs);
index f689bc10dcc9c2176adca14a83b3379f451485ac..4d78ec21048bf830e34ae0f9d5c6b9f1d8ded436 100644 (file)
@@ -758,10 +758,10 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
        now = time(0);
        diff = now - dev->bid_time;
 
-       if ((now < dev->bid_time) ||
-           (diff < BLKID_PROBE_MIN) || 
-           (dev->bid_flags & BLKID_BID_FL_VERIFIED &&
-            diff < BLKID_PROBE_INTERVAL))
+       if ((now > dev->bid_time) && (diff > 0) && 
+           ((diff < BLKID_PROBE_MIN) || 
+            (dev->bid_flags & BLKID_BID_FL_VERIFIED &&
+             diff < BLKID_PROBE_INTERVAL)))
                return dev;
 
        DBG(DEBUG_PROBE,
index c823d30dbb7bf1ba4b3e149cfd493ed5adc363c1..010d9f33a45b21160ac9f0227268a2e2e13973a5 100644 (file)
@@ -453,7 +453,7 @@ static void debug_dump_dev(blkid_dev dev)
 
        printf("  dev: name = %s\n", dev->bid_name);
        printf("  dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno);
-       printf("  dev: TIME=\"%lu\"\n", dev->bid_time);
+       printf("  dev: TIME=\"%ld\"\n", dev->bid_time);
        printf("  dev: PRI=\"%d\"\n", dev->bid_pri);
        printf("  dev: flags = 0x%08X\n", dev->bid_flags);
 
index a2fbd7b4521cb1e61e94252d7dd160b37a9a9af4..f52dc46b0228090f140e5ab288bf0af64f2ffdc6 100644 (file)
@@ -37,7 +37,7 @@ static int save_dev(blkid_dev dev, FILE *file)
            printf("device %s, type %s\n", dev->bid_name, dev->bid_type));
 
        fprintf(file,
-               "<device DEVNO=\"0x%04lx\" TIME=\"%lu\"",
+               "<device DEVNO=\"0x%04lx\" TIME=\"%ld\"",
                (unsigned long) dev->bid_devno, dev->bid_time);
        if (dev->bid_pri)
                fprintf(file, " PRI=\"%d\"", dev->bid_pri);