From miek at miek.nl Fri Dec 23 13:00:24 2011 From: miek at miek.nl (Miek Gieben) Date: Fri, 23 Dec 2011 14:00:24 +0100 Subject: [ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits) Message-ID: <20111223130024.GA14771@miek.nl> Hello, There seems to be a off-by-one bug in the function ldns_year_and_yday_from_days_since_epoch() in util.c See this thread on the opendssec list: http://lists.opendnssec.org/pipermail/opendnssec-user/2011-December/001501.html I think the patch below fixes things. Can some of the ldns maintainers take a second look? --- util.c.patch 2011-12-23 13:44:21.000000000 +0100 +++ util.c 2011-12-23 13:44:38.000000000 +0100 @@ -255,7 +255,7 @@ int year = 1970; int new_year; - while (days < 0 || days >= (int64_t) (is_leap_year(year) ? 366 : 365)) { + while (days < 0 || days > (int64_t) (is_leap_year(year) ? 366 : 365)) { new_year = year + (int) LDNS_DIV(days, 366); if (year == new_year) { year += days < 0 ? -1 : 1; grtz Miek -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From Willem at NLnetLabs.nl Fri Dec 23 21:21:19 2011 From: Willem at NLnetLabs.nl (Willem Toorop) Date: Fri, 23 Dec 2011 22:21:19 +0100 Subject: [ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits) In-Reply-To: <20111223130024.GA14771@miek.nl> References: <20111223130024.GA14771@miek.nl> Message-ID: <4EF4F0CF.9020103@NLnetLabs.nl> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ouch! Very nasty. A correct fix is attached. - -- willem Op 23-12-11 14:00, Miek Gieben schreef: > Hello, > > There seems to be a off-by-one bug in the function > ldns_year_and_yday_from_days_since_epoch() in util.c > > See this thread on the opendssec list: > http://lists.opendnssec.org/pipermail/opendnssec-user/2011-December/001501.html > > I think the patch below fixes things. Can some of the ldns > maintainers take a second look? > > --- util.c.patch 2011-12-23 13:44:21.000000000 +0100 +++ > util.c 2011-12-23 13:44:38.000000000 +0100 @@ -255,7 +255,7 > @@ int year = 1970; int new_year; > > - while (days < 0 || days >= (int64_t) (is_leap_year(year) ? > 366 : 365)) { + while (days < 0 || days > (int64_t) > (is_leap_year(year) ? 366 : 365)) { new_year = year + (int) > LDNS_DIV(days, 366); if (year == new_year) { year += days < 0 ? -1 > : 1; > > grtz Miek > > > > _______________________________________________ ldns-users mailing > list ldns-users at open.nlnetlabs.nl > http://open.nlnetlabs.nl/mailman/listinfo/ldns-users -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJO9PDJAAoJEOX4+CEvd6SYnDMP/ipLfuVLJ4JuiAgcfpe8mAAN UIbiLJSl5B74tayr2CBbhMocQ6UpjRqwMdyAZ2WJEUvHakOPLT92tqHlKlCI2Kty 1ahCaLQzOlSDxhSTigdN36U7lWOq6V1bEEujcbjmhtgWNka9Nau/LilL98PML1th 0CA3jQhNHeJ5YTKZDUr+4T36p8oIebNBiUtZ2OhB8MXGrZfbEWfRIQVr56M9EkDY 8AeUC30eqVhFKii//Cof2HF/uF04HOBTvaPAR0Pbs9aUe7SKAo+1olJ9orVhSUtl f6NiEGbWUdauuhMd4TJyFaegYfqAe2inv4mhLpE7oFhK7HyXZLu/CGY9LyZ/21CV s4ZgRde72Zaa0ZIAGtliUezPi5EbZY4h/QLAFy3W2hahywOHyGT40Paj9wpSKZId OgPecCD/m2ErffC4Va/ZU40XplZVU9Xdkcc81Aw18KHb0JdFDtRGumKD2lnc+Gtu KatsbwWFzDf9snS0Ou/qd7j0KYZeT93k5T8mjDuTrc24RIdypq55kWYAJoFR/ImA A19poNCyJwe1I7wTiZLCf9lNQIpvWzmWICUElqrcZb87VI1e5Nro0CIb1rQ2J6Om 4ZwGOtatdnQsJzrpjRtX560UHIPK0wHbc5htjgw97fPtLnIsZ0PS4WN6XeTRktSE 5sa16nNz/E4j5DcFVt8A =tXzf -----END PGP SIGNATURE----- -------------- next part -------------- A non-text attachment was scrubbed... Name: util.c.patch Type: text/x-patch Size: 450 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: util.c.patch.sig Type: application/octet-stream Size: 543 bytes Desc: not available URL: From Willem at NLnetLabs.nl Fri Dec 23 23:17:26 2011 From: Willem at NLnetLabs.nl (Willem Toorop) Date: Sat, 24 Dec 2011 00:17:26 +0100 Subject: [ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits) In-Reply-To: <4EF4F0CF.9020103@NLnetLabs.nl> References: <20111223130024.GA14771@miek.nl> <4EF4F0CF.9020103@NLnetLabs.nl> Message-ID: <4EF50C06.8030208@NLnetLabs.nl> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 A simpler solution is possible (and attached as a patch for 1.6.11)... - -- willem Op 23-12-11 22:21, Willem Toorop schreef: > Ouch! Very nasty. A correct fix is attached. -- willem -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJO9QwGAAoJEOX4+CEvd6SYNr0QAJfI0FkdJTVLzGHg5CFZFHJo F2lRmjC6CVm2mHgo/+P12QtWRIWlQiodtcfYQ96jI9gwNVKH873Ap5n6qPLvv7Ur qrTshbSWYLHF6Ln6PYMlXMTimTMsZnsSePBpDzU9Dwu+Fa7nSflUoBOd5/yJXN7S cVJESYn1q0DleGea4UiswrpNjixKRkIWthWBlEnyhWRegG2AWF2/f5YlJE9taFPG F80dvD6Mhla8oHgSInPKeZsSqTSqssEKYBm2lIGw5cxyl3UKb63e67KPVnO/aGK2 X4KzBecEcEEIVsXljslCjGj9pLk/R6YWOC/O+yLzzN9mMaftpQW25iK5oCytvA7A cM53DdSQu02paDeXobq4DeL0ME920QVeK8T60loIz7e9DopI3k2vrzJdZB879Le7 M+Fk653wxJhEkfDEHOCQODFeZR6wsBDVgJ/NTeEmXyZBpOEC9EUmp4mInWGRkzJ1 90WCSlMLEl0CYyWbeextmWkl1TaaBANt9Plc34wl//yD1EIhNrqqSGfI+nk5h2d2 IdahTteshG++sJ4NJsHhZICcb9UkneAyrhA/LU5qyXYaThHW1v5GaIwCyJJIEKUa SosK/sIZL9lYFCDmW8qaor1QuJpl4TqOYDx6MIuRkheJNtBySYjg5VmvFkTnMnHz VVueFyo4/sdPuXpq1Mb2 =cPw3 -----END PGP SIGNATURE----- -------------- next part -------------- A non-text attachment was scrubbed... Name: util.c.patch Type: text/x-patch Size: 503 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: util.c.patch.sig Type: application/octet-stream Size: 543 bytes Desc: not available URL: From miek at miek.nl Fri Dec 23 23:29:00 2011 From: miek at miek.nl (Miek Gieben) Date: Sat, 24 Dec 2011 00:29:00 +0100 Subject: [ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits) In-Reply-To: <4EF50C06.8030208@NLnetLabs.nl> References: <20111223130024.GA14771@miek.nl> <4EF4F0CF.9020103@NLnetLabs.nl> <4EF50C06.8030208@NLnetLabs.nl> Message-ID: <20111223232900.GA27652@miek.nl> [ Quoting at 00:17 on Dec 24 in "Re: [ldns-users] Bug..." ] > Index: util.c > =================================================================== > --- util.c (revision 3625) > +++ util.c (working copy) > @@ -256,10 +256,7 @@ > int new_year; > > while (days < 0 || days >= (int64_t) (is_leap_year(year) ? 366 : 365)) { > - new_year = year + (int) LDNS_DIV(days, 366); > - if (year == new_year) { > - year += days < 0 ? -1 : 1; > - } > + new_year = year + (int) LDNS_DIV(days, 365); > days -= (new_year - year) * 365; > days -= leap_days(year, new_year); > year = new_year; Looks OK. I can ask Tom to apply it locally and test it a little? (don't know if he's also on this list) grtz Miek -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From Willem at NLnetLabs.nl Fri Dec 23 23:54:41 2011 From: Willem at NLnetLabs.nl (Willem Toorop) Date: Sat, 24 Dec 2011 00:54:41 +0100 Subject: [ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits) In-Reply-To: <20111223232900.GA27652@miek.nl> References: <20111223130024.GA14771@miek.nl> <4EF4F0CF.9020103@NLnetLabs.nl> <4EF50C06.8030208@NLnetLabs.nl> <20111223232900.GA27652@miek.nl> Message-ID: <4EF514C1.1020407@NLnetLabs.nl> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Op 24-12-11 00:29, Miek Gieben schreef: > [ Quoting at 00:17 on Dec 24 in "Re: > [ldns-users] Bug..." ] >> Index: util.c >> =================================================================== >> >> - --- util.c (revision 3625) >> +++ util.c (working copy) @@ -256,10 +256,7 @@ int new_year; >> >> while (days < 0 || days >= (int64_t) (is_leap_year(year) ? 366 : >> 365)) { - new_year = year + (int) LDNS_DIV(days, 366); - if >> (year == new_year) { - year += days < 0 ? -1 : 1; - } + >> new_year = year + (int) LDNS_DIV(days, 365); days -= (new_year - >> year) * 365; days -= leap_days(year, new_year); year = >> new_year; > > Looks OK. I can ask Tom to apply it locally and test it a little? > (don't know if he's also on this list) I just subscribed to the openddnssec-user list (also in To:). I used the attached brute force test program (for 32 bits systems). I've also compared the result of ldns_gmtime64_r and gmtime_r for a broader range of values on a 64 bits system, but since ldns_gmtime64_r is local to util.c I have no ``external'' test program. The fix with replacing >= with > still produces some mismatches.. Sorry about all this. I think it somehow slipped in in earlier attempts (before LDNS_DIV and LDNS_MOD) to compensate for C's behaviour of the % and / operators for negative numbers (which is undefined b.t.w.). - -- willem -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJO9RTBAAoJEOX4+CEvd6SY/RAP/3JCGj7jcVHTuu48W+ZIjC3j 3WJ5DvkliY2w3HBjqNz3CWS6OpG106D2tsP9+HGDCpam0xzIvBEMyxshpSmA2+9d ceFXmTB45/cT91krqEIsAmgffndJDkL+1ESOd9OOZIuF2dC21g1KrygUK+Jz69BN dTFbyIHGn2G6wUs9jNyfGHY5XmZYKrlWjpLQykXqLALv5rz4j1X7AHtJOlikrOnt HL+UzA+EwSjpqYB+CFtc/Kkw/+OzUrB1q1mb4ZD8Pp7G42oKNIcZlOrQKhk/WrKb 9W4IqaC4v5noK300quW2CsiCuNhJ8a+ni4YulQUHkY3eOegTiQm8kiSQV0Ubfw2r PFduhsXWBcB4Q9lznRw10N5Jap4muUM5e22mt9RKemJvurvU0Do7VHKiofIiWrI4 ya2rX7MEVeJ9JsVz6KXs868qvrxAqGjA/JbRc340W8TFcTqdnGa+xIJpwqaHcT1M zPWenIa3xX3V8zVGhgt8FLtww+ybRLzu5yr9+Lbu17JDzf6ZAvKtEPUjji485lLz hN6QjHfBSot9Yq9xma05Xrd0RYrbwzYsVGVSuOVFOgPKYHcZznpSUC4MYWNY59JE DAFHf4PcvKhajcsZC0ZjelKMZdvImUZA2mlEO3G8fxky8bRBnce2v3fRSLiW1jXc IErEh6n5cEgc/fUtLi2J =wGzW -----END PGP SIGNATURE----- -------------- next part -------------- A non-text attachment was scrubbed... Name: ldns_year_and_yday_from_days_since_epoch_test.c Type: text/x-csrc Size: 1256 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ldns_year_and_yday_from_days_since_epoch_test.c.sig Type: application/octet-stream Size: 543 bytes Desc: not available URL: From tom at whyscream.net Tue Dec 27 00:26:27 2011 From: tom at whyscream.net (Tom Hendrikx) Date: Tue, 27 Dec 2011 01:26:27 +0100 Subject: [ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits) In-Reply-To: <20111223232900.GA27652@miek.nl> References: <20111223130024.GA14771@miek.nl> <4EF4F0CF.9020103@NLnetLabs.nl> <4EF50C06.8030208@NLnetLabs.nl> <20111223232900.GA27652@miek.nl> Message-ID: <4EF910B3.9070504@whyscream.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 24-12-11 00:29, Miek Gieben wrote: > [ Quoting at 00:17 on Dec 24 in "Re: > [ldns-users] Bug..." ] >> Index: util.c >> =================================================================== >> >> - --- util.c (revision 3625) >> +++ util.c (working copy) @@ -256,10 +256,7 @@ int new_year; >> >> while (days < 0 || days >= (int64_t) (is_leap_year(year) ? 366 : >> 365)) { - new_year = year + (int) LDNS_DIV(days, 366); - if >> (year == new_year) { - year += days < 0 ? -1 : 1; - } + >> new_year = year + (int) LDNS_DIV(days, 365); days -= (new_year - >> year) * 365; days -= leap_days(year, new_year); year = >> new_year; > > Looks OK. I can ask Tom to apply it locally and test it a little? > (don't know if he's also on this list) > I am, but not during the holidays. Will test tomorrow ;) - -- Tom -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBCAAGBQJO+RCtAAoJEJPfMZ19VO/1GwsQALaLC3IL7WkPmpScQEbKppF9 JpILRIx9IpeNdf880nXDDPto+xuPDT5CpaH7YNLVFJISk15sjjfbfkq1KaBWJEjT sxWCz/Uz1DOSh71YivYDiOZSDavnaWeTN1uiM1pjcDmRSEFuiXPCGX03rvidu4qW OFzBuKdYIYvsRe8rkyv4wWZ6brFec0AU4viSa946p2h3NsOA5l8fL3BtLJMw6jNP w+XQAaZsHwDZATINyH8vCbcYcfOY3p2zBBR1NdsVcsUKXoxBUfRj4H9+DxS13FFQ yd8EOAWePT6hO2ezX7rSWWnaZCxH6hyF+XHbkjaNDt9vkbRjSAU/LC8ATg1AhW9P YEmt8aNxF91EtYiy84jVWnQFq16kUJ6dwLXLkel4EMpoZAEj2UXq/z7lqFdDApVg 6sT4ox+V40c4Y1isOwGgXUGf/IoXWkVJdY9+i/ubi7p8Irqq7tWFuQ1TVOs7sSot mHbqD6dl5cqNZYz8UNhUQh5W+89vYCFuKd9MhqjbBgLynwm6o92MmO8PlljY99XZ d+dLyrV44kmlAFnYwA9JbwHZNLrIgMwR1+ug1NCW3pXGhSbcLxbuxjOMc1x8lpO+ Z5lR2vUraquJZyvG16rsYKIUsJ+ugZozkLav5Qd7fsUU7OYCxBhAshc//zmlk49R qQbZmr6k4TRmnKe5FQ2d =aRGR -----END PGP SIGNATURE----- From tom at whyscream.net Tue Dec 27 15:28:01 2011 From: tom at whyscream.net (Tom Hendrikx) Date: Tue, 27 Dec 2011 16:28:01 +0100 Subject: [ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits) In-Reply-To: <4EF910B3.9070504@whyscream.net> References: <20111223130024.GA14771@miek.nl> <4EF4F0CF.9020103@NLnetLabs.nl> <4EF50C06.8030208@NLnetLabs.nl> <20111223232900.GA27652@miek.nl> <4EF910B3.9070504@whyscream.net> Message-ID: <4EF9E401.7050601@whyscream.net> On 12/27/2011 01:26 AM, Tom Hendrikx wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > On 24-12-11 00:29, Miek Gieben wrote: >> [ Quoting at 00:17 on Dec 24 in "Re: >> [ldns-users] Bug..." ] >>> Index: util.c >>> =================================================================== >>> >>> > - --- util.c (revision 3625) >>> +++ util.c (working copy) @@ -256,10 +256,7 @@ int new_year; >>> >>> while (days< 0 || days>= (int64_t) (is_leap_year(year) ? 366 : >>> 365)) { - new_year = year + (int) LDNS_DIV(days, 366); - if >>> (year == new_year) { - year += days< 0 ? -1 : 1; - } + >>> new_year = year + (int) LDNS_DIV(days, 365); days -= (new_year - >>> year) * 365; days -= leap_days(year, new_year); year = >>> new_year; >> >> Looks OK. I can ask Tom to apply it locally and test it a little? >> (don't know if he's also on this list) >> > > I am, but not during the holidays. Will test tomorrow ;) > Since Opendnssec no longer reproduces this error due to time moving on, I setup an nsd box with a zone where I can easily reproduce this issue: 'drill -D soa example.net @178.18.84.173' should trigger the issue on a 32-bit box. The actual data that nsd is sending, is correct (expiration = 20120101224910), but drill reports expiration = 20121231224910. After applying willems patch to ldns, drill shows the correct result. i'm not sure how to test this more properly, but feel free to reproduce. I'll leave the nsd instance running for some time. -- Tom