diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2010-06-09 15:47:15 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2010-06-09 15:47:15 +0000 |
commit | a68d5fa9b8b87140378ef4f0b20b981cfd24ad77 (patch) | |
tree | f4c7ba301fbc6345fe5abd8726d55d9dedbd7fad | |
parent | e7be2376f5a5ad6739b6c9fde5053aad5d01e444 (diff) |
Do not set time 100 years in the future if the time read is before
POSIX_BASE_YEAR (1970) because the clock's base year is before that year as
well (as found on sparc which use 1968 as their base year); this allows
clocks with dead batteries to ``correctly'' report the current date as in year
1968, instead of year 2068 which causes a 32 bit time_t wraparound in year
1931.
Found the hard way by Philippe Meunier, ok deraadt@
-rw-r--r-- | sys/dev/ic/mk48txx.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/sys/dev/ic/mk48txx.c b/sys/dev/ic/mk48txx.c index 9b4b083f0eb..a9e537a8b44 100644 --- a/sys/dev/ic/mk48txx.c +++ b/sys/dev/ic/mk48txx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mk48txx.c,v 1.5 2008/06/26 05:42:15 ray Exp $ */ +/* $OpenBSD: mk48txx.c,v 1.6 2010/06/09 15:47:14 miod Exp $ */ /* $NetBSD: mk48txx.c,v 1.7 2001/04/08 17:05:10 tsutsui Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -156,7 +156,8 @@ mk48txx_gettime(handle, tv) year = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_IYEAR)); year += mk->mk_year0; - if (year < POSIX_BASE_YEAR && mk48txx_auto_century_adjust != 0) + if (year < POSIX_BASE_YEAR && mk48txx_auto_century_adjust != 0 && + mk->mk_year0 >= POSIX_BASE_YEAR) year += 100; dt.dt_year = year; |