From owner-p4-projects@FreeBSD.ORG Thu Aug 19 02:05:19 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C1D7C16A4D0; Thu, 19 Aug 2004 02:05:18 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9279E16A4CE for ; Thu, 19 Aug 2004 02:05:18 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 89A5143D73 for ; Thu, 19 Aug 2004 02:05:18 +0000 (GMT) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i7J25IXl007387 for ; Thu, 19 Aug 2004 02:05:18 GMT (envelope-from peter@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i7J25Ij8007384 for perforce@freebsd.org; Thu, 19 Aug 2004 02:05:18 GMT (envelope-from peter@freebsd.org) Date: Thu, 19 Aug 2004 02:05:18 GMT Message-Id: <200408190205.i7J25Ij8007384@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter@freebsd.org using -f From: Peter Wemm To: Perforce Change Reviews Subject: PERFORCE change 60029 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2004 02:05:19 -0000 http://perforce.freebsd.org/chv.cgi?CH=60029 Change 60029 by peter@peter_daintree on 2004/08/19 02:04:36 For a 32 bit time_t machine, the representable years range from approx 1902 through 2038. Nothing has to worry about negative tm_year values. Lots of funny things happened to the calendar over the preceding few centuries that are not covered in the time system here. However, 64 bit time_t systems can represent tm_year for the next few billion years without an overflow. And it is signed, so theoretically it can represent 1900+year for the last few billion years. But, we dont have the calendar munging so this is of little value. So, clamp the tm_year values as >= 0, both for POLA and as a convenient safety test. A totally null 'struct tm' is 'jan 0, 1900, 00:00:00'. But there isn't a 0th day in the month, so it is normalized to 'dec 31, 1899, 00:00:00'. Adding the < 0 test means we catch this input value which is fairly likely to have been bogus from the start. Affected files ... .. //depot/projects/hammer/lib/libc/stdtime/localtime.c#6 edit Differences ... ==== //depot/projects/hammer/lib/libc/stdtime/localtime.c#6 (text+ko) ==== @@ -1487,6 +1487,9 @@ } if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE)) return WRONG; + /* Don't go below 1900 for POLA */ + if (yourtm.tm_year < 0) + return WRONG; if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN) saved_seconds = 0; else if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) {