From nobody Mon Jul 10 16:34:42 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R08jd3ywXz2trj5; Mon, 10 Jul 2023 16:34:45 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from omta002.cacentral1.a.cloudfilter.net (omta002.cacentral1.a.cloudfilter.net [3.97.99.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R08jd20vSz3Jcp; Mon, 10 Jul 2023 16:34:45 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Authentication-Results: mx1.freebsd.org; none Received: from shw-obgw-4001a.ext.cloudfilter.net ([10.228.9.142]) by cmsmtp with ESMTP id IpF3qPEC96NwhItqWq0eWx; Mon, 10 Jul 2023 16:34:44 +0000 Received: from spqr.komquats.com ([70.66.152.170]) by cmsmtp with ESMTPA id ItqVq0KJEHFsOItqVqdH6f; Mon, 10 Jul 2023 16:34:44 +0000 X-Authority-Analysis: v=2.4 cv=XZqaca15 c=1 sm=1 tr=0 ts=64ac3324 a=y8EK/9tc/U6QY+pUhnbtgQ==:117 a=y8EK/9tc/U6QY+pUhnbtgQ==:17 a=kj9zAlcOel0A:10 a=ws7JD89P4LkA:10 a=6I5d2MoRAAAA:8 a=iLNU1ar6AAAA:8 a=YxBL1-UpAAAA:8 a=EkcXrb_YAAAA:8 a=xwsD0MZEt68H0K3cZ-YA:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 a=Ia-lj3WSrqcvXOmTRaiG:22 a=LK5xJRSDVpKd5WXXoEvA:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTP id A634A190; Mon, 10 Jul 2023 09:34:42 -0700 (PDT) Received: by slippy.cwsent.com (Postfix, from userid 1000) id 8CE952D; Mon, 10 Jul 2023 09:34:42 -0700 (PDT) X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.8+dev Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Eric van Gyzen cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: c210cac00f25 - main - dhclient: fix time parsing for leases expiring after 2038 In-reply-to: <202307101600.36AG0xNe015335@gitrepo.freebsd.org> References: <202307101600.36AG0xNe015335@gitrepo.freebsd.org> Comments: In-reply-to Eric van Gyzen message dated "Mon, 10 Jul 2023 16:00:59 +0000." List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 10 Jul 2023 09:34:42 -0700 Message-Id: <20230710163442.8CE952D@slippy.cwsent.com> X-CMAE-Envelope: MS4xfCNacDWDiRf6AUChd4o0XVltRiPC93vulbk1UPccqxQgkGgEgI7/H2kjJWlwe8EbMGR724SWO7PJjDnkINU0RlDy1Ut+vvLF0gm1oyRovg0VaJ6rCQwK cIsTXWBlplrS1/1OGqxDVYgdyxCfUUbFhbAAqLvGI5oNe+vt4hjpaK9wbFLeyMXWkq8K+pI8nLnNF4dYmSAGqb5MM6E8UACro7nEI5Cl9Vorsu8WTWZF7aSY gUOEyGWMd6Tt8T9jIchKC0EJYAcS7OKh+b2EaPh0Dj6edjFrmy/ilShDiKepdSoQpbzM3YzEaRtWSdYIy5e+I3eryx1pZ/LtNVNocYA4SYA= X-Rspamd-Queue-Id: 4R08jd20vSz3Jcp X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:16509, ipnet:3.96.0.0/15, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N In message <202307101600.36AG0xNe015335@gitrepo.freebsd.org>, Eric van Gyzen wr ites: > The branch main has been updated by vangyzen: > > URL: https://cgit.FreeBSD.org/src/commit/?id=c210cac00f2584f031b56b4cdd2e801d > bb9e1348 > > commit c210cac00f2584f031b56b4cdd2e801dbb9e1348 > Author: Alex Bahm > AuthorDate: 2023-07-10 15:56:05 +0000 > Commit: Eric van Gyzen > CommitDate: 2023-07-10 16:00:34 +0000 > > dhclient: fix time parsing for leases expiring after 2038 > > Convert lease parsing to timegm to calculate timestamp. For reference, wh > en > writing the lease, we use gmtime to convert the timestamp to struct tm. > > Reviewed By: markj, vangyzen > MFC after: 2 weeks > Sponsored by: Dell EMC Isilon > Differential Revision: https://reviews.freebsd.org/D40760 > --- > sbin/dhclient/parse.c | 28 ++----------------- > sbin/dhclient/tests/Makefile | 3 +- > sbin/dhclient/tests/fake.c | 15 ++++++++++ > sbin/dhclient/tests/option-domain-search.c | 45 ++++++++++++++++++++++++++++ > ++ > 4 files changed, 64 insertions(+), 27 deletions(-) > > diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c > index 4018f70f3a5d..70e2013d0813 100644 > --- a/sbin/dhclient/parse.c > +++ b/sbin/dhclient/parse.c > @@ -444,9 +444,7 @@ convert_num(unsigned char *buf, char *str, unsigned base, > int size) > time_t > parse_date(FILE *cfile) > { > - static int months[11] = { 31, 59, 90, 120, 151, 181, > - 212, 243, 273, 304, 334 }; > - int guess, token; > + int token; > struct tm tm; > char *val; > > @@ -570,27 +568,5 @@ parse_date(FILE *cfile) > return (0); > } > > - /* Guess the time value... */ > - guess = ((((((365 * (tm.tm_year - 70) + /* Days in years since '70 */ > - (tm.tm_year - 69) / 4 + /* Leap days since '70 */ > - (tm.tm_mon /* Days in months this year */ > - ? months[tm.tm_mon - 1] > - : 0) + > - (tm.tm_mon > 1 && /* Leap day this year */ > - !((tm.tm_year - 72) & 3)) + > - tm.tm_mday - 1) * 24) + /* Day of month */ > - tm.tm_hour) * 60) + > - tm.tm_min) * 60) + tm.tm_sec; > - > - /* > - * This guess could be wrong because of leap seconds or other > - * weirdness we don't know about that the system does. For > - * now, we're just going to accept the guess, but at some point > - * it might be nice to do a successive approximation here to get > - * an exact value. Even if the error is small, if the server > - * is restarted frequently (and thus the lease database is > - * reread), the error could accumulate into something > - * significant. > - */ > - return (guess); > + return (timegm(&tm)); > } > diff --git a/sbin/dhclient/tests/Makefile b/sbin/dhclient/tests/Makefile > index ce4c7acb822e..790d3dbcccce 100644 > --- a/sbin/dhclient/tests/Makefile > +++ b/sbin/dhclient/tests/Makefile > @@ -6,7 +6,8 @@ ATF_TESTS_SH= pcp > > PLAIN_TESTS_C= option-domain-search_test > SRCS.option-domain-search_test= alloc.c convert.c hash.c option > s.c \ > - tables.c fake.c option-domain-search.c > + tables.c parse.c conflex.c tree.c fake. > c \ > + option-domain-search.c > CFLAGS.option-domain-search_test+= -I${.CURDIR:H} > LIBADD.option-domain-search_test= util > > diff --git a/sbin/dhclient/tests/fake.c b/sbin/dhclient/tests/fake.c > index 6a170953beb0..17b721527f04 100644 > --- a/sbin/dhclient/tests/fake.c > +++ b/sbin/dhclient/tests/fake.c > @@ -7,6 +7,7 @@ > #include "dhcpd.h" > > extern jmp_buf env; > +int warnings_occurred; > > void > error(const char *fmt, ...) > @@ -52,6 +53,20 @@ note(const char *fmt, ...) > return ret; > } > > +int > +parse_warn(const char *fmt, ...) > +{ > + int ret; > + va_list ap; > + > + va_start(ap, fmt); > + ret = vfprintf(stderr, fmt, ap); > + va_end(ap); > + fprintf(stderr, "\n"); > + > + return ret; > +} > + > void > bootp(struct packet *packet) > { > diff --git a/sbin/dhclient/tests/option-domain-search.c b/sbin/dhclient/tests > /option-domain-search.c > index b79f9a560137..a3517c9c1dc1 100644 > --- a/sbin/dhclient/tests/option-domain-search.c > +++ b/sbin/dhclient/tests/option-domain-search.c > @@ -303,6 +303,49 @@ multiple_domains_valid() > free(option->data); > } > > +static > +void > +parse_date_helper(const char *string, time_t timestamp) > +{ > + int ret = 0; > + FILE *file = NULL; > + time_t ts; > + > + file = fopen("/tmp/dhclient.test", "w"); > + if (!file) > + abort(); > + > + ret = fwrite(string, strlen(string), 1, file); > + if (ret <= 0) > + abort(); > + > + fclose(file); > + > + file = fopen("/tmp/dhclient.test", "r"); > + if (!file) > + abort(); > + > + new_parse("test"); > + ts = parse_date(file); > + if (ts != timestamp) > + abort(); > + > + fclose(file); > +} > + > +void > +parse_date_valid(void) > +{ > + int ret; > + > + ret = setjmp(env); > + if (ret != 0) > + abort(); > + > + parse_date_helper(" 2 2024/7/2 20:25:50;\n", 1719951950); > + parse_date_helper(" 1 2091/7/2 20:25:50;\n", 3834246350); > +} > + > int > main(int argc, char *argv[]) > { > @@ -324,5 +367,7 @@ main(int argc, char *argv[]) > > multiple_domains_valid(); > > + parse_date_valid(); > + > return (0); > } > This fails to build on i386. ===> libexec/bootpd/tools/bootptest (all) --- all_subdir_sbin --- /opt/src/git-src/sbin/dhclient/tests/option-domain-search.c:346:47: error: implicit conversion from 'long long' to 'time_t' (aka 'int') changes value from 3834246350 to -460720946 [-Werror,-Wconstant-conversion] parse_date_helper(" 1 2091/7/2 20:25:50;\n", 3834246350); ~~~~~~~~~~~~~~~~~ ^~~~~~~~~~ 1 error generated. 4.16 real 0.37 user 0.36 sys make[1]: stopped in /opt/src/git-src make: stopped in /opt/src/git-src _buildsys 58228 - - i386 build failed, continuing _buildsys 58233 - - i386 failed: build failure _buildsys 58238 - - exiting, RC=0: /usr/local/bin/_buildsys -x -uz -Nb -Ai386 -j8 Finished Mon Jul 10 09:31:24 PDT 2023, RC=0 -- Cheers, Cy Schubert FreeBSD UNIX: Web: https://FreeBSD.org NTP: Web: https://nwtime.org e^(i*pi)+1=0