Hi all, 

I've recently observed that the hwclock command sometimes gives 31.Dec 23:59:59 
as output (smells like -1, does it). A quick look at the code brought up that 
the hwclock applet uses the output of mktime without error checking. 
I've fixed this by checking the return value of read_rtc and giving an error 
message if it is -1. I've attached a patch that works for me and doesn't give 
out the wrong time any more if the RTC driver reads garbage. 

Regards, 
Steve


diff -uNr busybox-1.5.0/util-linux/hwclock.c 
busybox-1.5.0-mod/util-linux/hwclock.c
--- busybox-1.5.0/util-linux/hwclock.c  2007-03-22 21:21:39.000000000 +0100
+++ busybox-1.5.0-mod/util-linux/hwclock.c      2007-03-29 13:53:14.000000000 
+0200
@@ -106,6 +107,11 @@
        RESERVE_CONFIG_BUFFER(buffer, 64);
 
        t = read_rtc(utc);
+       if(t == (time_t)-1) {
+               RELEASE_CONFIG_BUFFER(buffer);
+               bb_error_msg_and_die("invalid RTC time !");
+       }
+
        ptm = localtime(&t);  /* Sets 'tzname[]' */
 
        safe_strncpy(buffer, ctime(&t), 64);
@@ -125,6 +131,8 @@
        const struct timezone tz = { timezone/60 - 60*daylight, 0 };
 
        tv.tv_sec = read_rtc(utc);
+       if(tv.tv_sec == (time_t)-1)
+               bb_error_msg_and_die("invalid RTC time !");
 
        if (settimeofday(&tv, &tz))
                bb_perror_msg_and_die("settimeofday() failed");

_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to