[ldns-users] Bug in ldns_year_and_yday_from_days_since_epoch (only on 32 bits)

Willem Toorop Willem at NLnetLabs.nl
Fri Dec 23 23:54:41 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Op 24-12-11 00:29, Miek Gieben schreef:
> [ Quoting <Willem at NLnetLabs.nl> 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: <http://lists.nlnetlabs.nl/pipermail/ldns-users/attachments/20111224/c727fefb/attachment.bin>
-------------- 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: <http://lists.nlnetlabs.nl/pipermail/ldns-users/attachments/20111224/c727fefb/attachment.obj>


More information about the ldns-users mailing list