hwclock: check errno after strto..()

Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-06-21 15:00:40 +02:00
parent c9eea1b354
commit 9bf8088f25
1 changed files with 2 additions and 1 deletions

View File

@ -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;
}