]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: add iso-8601 overflow check
authorJ William Piggott <elseifthen@gmx.com>
Mon, 25 Sep 2017 23:30:24 +0000 (19:30 -0400)
committerKarel Zak <kzak@redhat.com>
Thu, 14 Dec 2017 14:32:13 +0000 (15:32 +0100)
hwclock wasn't testing for strtimeval_iso() truncation:

/sbin/hwclock --utc --noadjfile --predict --date '7982 years'; echo $?
9999-09-25 19:33:01.000000-0400
0

/sbin/hwclock --utc --noadjfile --predict --date '7983 years'; echo $?
10000-09-25 19:33:10.000000-
0

Patched:
./hwclock --utc --noadjfile --predict --date '7982 years'; echo $?
9999-09-25 19:22:15.000000-0400
0

./hwclock --utc --noadjfile --predict --date '7983 years'; echo $?
hwclock: iso-8601 format truncated
1

Signed-off-by: J William Piggott <elseifthen@gmx.com>
sys-utils/hwclock.c

index 36b6204b01dde4457af4221b82c0157029f28a98..c2c20812c888944eac9f312ff01ffd69a0e73afe 100644 (file)
@@ -551,15 +551,19 @@ set_hardware_clock_exact(const struct hwclock_control *ctl,
        set_hardware_clock(ctl, newhwtime);
 }
 
-static void
+static int
 display_time(struct timeval hwctime)
 {
        char buf[ISO_8601_BUFSIZ];
 
-       strtimeval_iso(&hwctime, ISO_8601_DATE|ISO_8601_TIME|ISO_8601_DOTUSEC|
+       if (strtimeval_iso(&hwctime, ISO_8601_DATE|ISO_8601_TIME|ISO_8601_DOTUSEC|
                                 ISO_8601_TIMEZONE|ISO_8601_SPACE,
-                                buf, sizeof(buf));
+                                buf, sizeof(buf))) {
+               warnx(_("iso-8601 format overflow"));
+               return EXIT_FAILURE;
+       }
        printf("%s\n", buf);
+       return EXIT_SUCCESS;
 }
 
 /*
@@ -931,8 +935,7 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
                        printf(_ ("Target date:   %ld\n"), set_time);
                        printf(_ ("Predicted RTC: %ld\n"), hclocktime.tv_sec);
                }
-               display_time(hclocktime);
-               return EXIT_SUCCESS;
+               return display_time(hclocktime);
        }
 
        if (ctl->systz)
@@ -978,7 +981,7 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
                 time_inc(hclocktime, time_diff(startup_time, read_time));
        }
        if (ctl->show || ctl->get) {
-               display_time(startup_hclocktime);
+               return display_time(startup_hclocktime);
        } else if (ctl->set) {
                set_hardware_clock_exact(ctl, set_time, startup_time);
                if (!ctl->noadjfile)