summaryrefslogtreecommitdiffstats
path: root/sys-utils/hwclock.c
diff options
context:
space:
mode:
authorJ William Piggott2017-09-26 01:30:24 +0200
committerJ William Piggott2017-11-10 21:49:45 +0100
commit10191da63a35317aea1d2286225efc03734c10d5 (patch)
treec6169c6d1ba8c6f0300acd97307dbf66df1af99e /sys-utils/hwclock.c
parentnsenter: revert changes committed by accident (diff)
downloadkernel-qcow2-util-linux-10191da63a35317aea1d2286225efc03734c10d5.tar.gz
kernel-qcow2-util-linux-10191da63a35317aea1d2286225efc03734c10d5.tar.xz
kernel-qcow2-util-linux-10191da63a35317aea1d2286225efc03734c10d5.zip
hwclock: add iso-8601 overflow check
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>
Diffstat (limited to 'sys-utils/hwclock.c')
-rw-r--r--sys-utils/hwclock.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 36b6204b0..c2c20812c 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -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)