From: Jeffrey Walton Date: Thu, 5 Mar 2020 21:13:09 +0000 (-0500) Subject: Fix UBsan finding (GH #71) X-Git-Tag: 1.8.0-rc.1~62^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae65df048d7359951fa2ddabc7ae52c7270641e6;p=thirdparty%2Fldns.git Fix UBsan finding (GH #71) Also see https://github.com/NLnetLabs/unbound/commit/57bbbfc0e6d9, where Unbound clared a similar finding with uint32_t casts. --- diff --git a/util.c b/util.c index 1216134f..fb129e12 100644 --- 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) {