s4:dns_server: use NUMERIC_CMP in rec_cmp()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 4 Apr 2024 01:22:24 +0000 (14:22 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 10 Apr 2024 22:56:33 +0000 (22:56 +0000)
dnsp_DnssrvRpcRecord.dwTimeStamp is uint32_t, making overflow possible.

dnsp_DnssrvRpcRecord.wType is an enum, which has the size of an int,
though it may be hard to set it to overflowing values.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dns_server/dnsserver_common.c

index 0e2b25a3ee743c0947d71b9da7521459c7efa778..d82e309f982a3aa87f0598de9313051df9d62d6e 100644 (file)
@@ -642,7 +642,7 @@ static int rec_cmp(const struct dnsp_DnssrvRpcRecord *r1,
                 * The records are sorted with higher types first,
                 * which puts tombstones (type 0) last.
                 */
-               return r2->wType - r1->wType;
+               return NUMERIC_CMP(r2->wType, r1->wType);
        }
        /*
         * Then we need to sort from the oldest to newest timestamp.
@@ -650,7 +650,7 @@ static int rec_cmp(const struct dnsp_DnssrvRpcRecord *r1,
         * Note that dwTimeStamp == 0 (never expiring) records come first,
         * then the ones whose expiry is soonest.
         */
-       return r1->dwTimeStamp - r2->dwTimeStamp;
+       return NUMERIC_CMP(r1->dwTimeStamp, r2->dwTimeStamp);
 }
 
 /*