From owner-freebsd-bugs Thu Jan 20 21:44: 1 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 9FCDE155EC for ; Thu, 20 Jan 2000 21:43:54 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id VAA14558; Thu, 20 Jan 2000 21:40:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Thu, 20 Jan 2000 21:40:02 -0800 (PST) Message-Id: <200001210540.VAA14558@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: "Sergey N. Voronkov" Subject: Re: bin/15872: Y2k bug in at(1) Reply-To: "Sergey N. Voronkov" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/15872; it has been noted by GNATS. From: "Sergey N. Voronkov" To: cjc@cc942873-a.ewndsr1.nj.home.com Cc: FreeBSD-gnats-submit@FreeBSD.ORG, sheldonh@uunet.co.za Subject: Re: bin/15872: Y2k bug in at(1) Date: Fri, 21 Jan 2000 10:28:10 +0500 (YEKT) > > if (year > 99) { > > if (year > 1899) > > year -= 1900; > > else > > panic("garbled time"); > > } ... > > What odd code. :-) > > I'd fix this by making proper tm_year adjustments before those calls to > assign_date() which pass it a tm_year value. > > Have you chatted to the authors? Are they unreachable? > > Ciao, > Sheldon. > > Index: parsetime.c > =================================================================== > RCS file: /home/ncvs/src/usr.bin/at/parsetime.c,v > retrieving revision 1.19 [...] It's another way to do this right. I'v adapted OpenBSD Team patch . And, Mr. Sheldon, can you, please, make one of two changes in STABLE branch ? Best Regards, Sergey N. Voronkov. --- /usr/src/usr.bin/at/parsetime.c Sun Aug 29 21:25:26 1999 +++ parsetime.c Fri Jan 21 10:21:56 2000 @@ -417,27 +417,30 @@ static void assign_date(struct tm *tm, long mday, long mon, long year) { - if (year > 99) { - if (year > 1899) - year -= 1900; - else - panic("garbled time"); - } else if (year != -1) { + + /* + * Convert year into tm_year format (year - 1900). + * We may be given the year in 2 digit, 4 digit, or tm_year format. + */ +#define TM_YEAR_BASE 1900 + if (year != -1) { struct tm *lt; time_t now; time(&now); lt = localtime(&now); - /* - * check if the specified year is in the next century. - * allow for one year of user error as many people will - * enter n - 1 at the start of year n. - */ - if (year < (lt->tm_year % 100) - 1) - year += 100; - /* adjust for the year 2000 and beyond */ - year += lt->tm_year - (lt->tm_year % 100); + if (year >= TM_YEAR_BASE) + year -= TM_YEAR_BASE; /* convert from 4 digit year */ + else if (year < 100) { + /* Convert to tm_year assuming current century */ + year += (lt->tm_year / 100) * 100; + + if (year == lt->tm_year - 1) + year++; /* Common off by one error */ + else if (year < lt->tm_year) + year += 100; /* must be in next century */ + } } if (year < 0 && To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message