]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Fix UBsan finding (GH #71) 83/head
authorJeffrey Walton <noloader@gmail.com>
Thu, 5 Mar 2020 21:13:09 +0000 (16:13 -0500)
committerJeffrey Walton <noloader@gmail.com>
Thu, 5 Mar 2020 21:13:09 +0000 (16:13 -0500)
Also see https://github.com/NLnetLabs/unbound/commit/57bbbfc0e6d9, where Unbound clared a similar finding with uint32_t casts.

util.c

diff --git a/util.c b/util.c
index 1216134f962cb3a40b4ffad1f089ea26e9d20c7f..fb129e1284f3a1e8d5c96e3dd143ad35827f6358 100644 (file)
--- a/util.c
+++ b/util.c
@@ -295,11 +295,11 @@ ldns_gmtime64_r(int64_t clock, struct tm *result)
 static int64_t
 ldns_serial_arithmitics_time(int32_t time, time_t now)
 {
-       int32_t offset = time - (int32_t) now;
+       /* Casting due to https://github.com/NLnetLabs/ldns/issues/71 */
+       int32_t offset = (int32_t) ((uint32_t) time - (uint32_t) now);
        return (int64_t) now + offset;
 }
 
-
 struct tm *
 ldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result)
 {