From e324b250593a32680309015eba7c6c5db7851227 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 12 Mar 2006 23:25:15 -0500 Subject: [PATCH] Fix blkid's last verification logic to work when the system clock is insane 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" --- lib/blkid/ChangeLog | 16 ++++++++++++++++ lib/blkid/dev.c | 2 +- lib/blkid/devname.c | 2 ++ lib/blkid/probe.c | 8 ++++---- lib/blkid/read.c | 2 +- lib/blkid/save.c | 2 +- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index 094f922..e0dac82 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,19 @@ +2006-03-12 Theodore Ts'o + + * 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 * probe.c (probe_ext3): If the filesystem has an external journal, diff --git a/lib/blkid/dev.c b/lib/blkid/dev.c index adb855a..ea2ccea 100644 --- a/lib/blkid/dev.c +++ b/lib/blkid/dev.c @@ -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); diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c index 0a13c47..b2ff40f 100644 --- a/lib/blkid/devname.c +++ b/lib/blkid/devname.c @@ -15,6 +15,7 @@ #include #include +#include #if HAVE_UNISTD_H #include #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); diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index f689bc1..4d78ec2 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -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, diff --git a/lib/blkid/read.c b/lib/blkid/read.c index c823d30..010d9f3 100644 --- a/lib/blkid/read.c +++ b/lib/blkid/read.c @@ -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); diff --git a/lib/blkid/save.c b/lib/blkid/save.c index a2fbd7b..f52dc46 100644 --- a/lib/blkid/save.c +++ b/lib/blkid/save.c @@ -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, - "bid_devno, dev->bid_time); if (dev->bid_pri) fprintf(file, " PRI=\"%d\"", dev->bid_pri); -- 1.8.3.1