s4:dsdb:util_trusts: simplify the NULL case in dns_cmp
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 1 May 2024 04:26:14 +0000 (16:26 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 7 May 2024 23:25:35 +0000 (23:25 +0000)
In this comparison function a NULL string is treated as the ancestor
of all names, but you need to look hard to see that.

By pulling the logic for NULLs to the front, hopefully we have to look
less hard.

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

index 2d82d6918d5275ab885f8a083dc2eea7d33c1581..dcd4d315dda7666654b7533eac61c4a2712b6a61 100644 (file)
@@ -648,14 +648,20 @@ static int dns_cmp(const char *s1, const char *s2)
        uint16_t comp2[UINT8_MAX] = {0};
        size_t i;
 
-       if (s1 != NULL) {
-               l1 = strlen(s1);
+       if (s1 == s2) {
+               /* this includes the both NULL case */
+               return DNS_CMP_MATCH;
        }
-
-       if (s2 != NULL) {
-               l2 = strlen(s2);
+       if (s1 == NULL) {
+               return DNS_CMP_SECOND_IS_CHILD;
+       }
+       if (s2 == NULL) {
+               return DNS_CMP_FIRST_IS_CHILD;
        }
 
+       l1 = strlen(s1);
+       l2 = strlen(s2);
+
        /*
         * trailing '.' are ignored.
         */