From 9bf8088f258a9b213886e3c663b8e57a3b65bfd3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 21 Jun 2021 15:00:40 +0200 Subject: [PATCH] hwclock: check errno after strto..() Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak --- sys-utils/hwclock-rtc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c index 7f1f0b6634..07af9c83c3 100644 --- a/sys-utils/hwclock-rtc.c +++ b/sys-utils/hwclock-rtc.c @@ -425,10 +425,11 @@ int set_epoch_rtc(const struct hwclock_control *ctl) int rtc_fd; unsigned long epoch; + errno = 0; epoch = strtoul(ctl->epoch_option, NULL, 10); /* There were no RTC clocks before 1900. */ - if (epoch < 1900 || epoch == ULONG_MAX) { + if (errno || epoch < 1900 || epoch == ULONG_MAX) { warnx(_("invalid epoch '%s'."), ctl->epoch_option); return 1; } -- 2.47.3