diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-03-27 14:03:20 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-03-27 14:03:20 +0000 |
commit | f11fb4e250fc57367b92304c47f19aacd6832a64 (patch) | |
tree | 25e66d917ff03e2b517aaf483fb648d97ed5a61e /sys/dev | |
parent | 901f21f9f54caac097e216648b4fd23c0ea9562d (diff) |
Reject times in the first year that can be represented by the clock to catch
RTC clocks that aren't battery powered.
ok deraadt@, millert@, visa@, tom@
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/fdt/sxirtc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/dev/fdt/sxirtc.c b/sys/dev/fdt/sxirtc.c index fd61fc043ee..1bc5a689372 100644 --- a/sys/dev/fdt/sxirtc.c +++ b/sys/dev/fdt/sxirtc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxirtc.c,v 1.1 2017/01/21 08:26:49 patrick Exp $ */ +/* $OpenBSD: sxirtc.c,v 1.2 2017/03/27 14:03:19 kettenis Exp $ */ /* * Copyright (c) 2008 Mark Kettenis * Copyright (c) 2013 Artturi Alm @@ -152,6 +152,14 @@ sxirtc_gettime(todr_chip_handle_t handle, struct timeval *tv) dt.dt_mon > 12 || dt.dt_mon == 0) return 1; + /* + * Reject the first year that can be represented by the clock. + * This avoids reporting a bogus time if the RTC isn't battery + * powered. + */ + if (dt.dt_year == sc->base_year) + return 1; + tv->tv_sec = clock_ymdhms_to_secs(&dt); tv->tv_usec = 0; return 0; |