From: Douglas Bagnall Date: Wed, 1 May 2024 04:26:14 +0000 (+1200) Subject: s4:dsdb:util_trusts: simplify the NULL case in dns_cmp X-Git-Tag: tdb-1.4.11~831 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b37186cf917ba9416b9d255e2d00d24cb8d12347;p=thirdparty%2Fsamba.git s4:dsdb:util_trusts: simplify the NULL case in dns_cmp 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 Reviewed-by: Andrew Bartlett --- diff --git a/source4/dsdb/common/util_trusts.c b/source4/dsdb/common/util_trusts.c index 2d82d6918d5..dcd4d315dda 100644 --- a/source4/dsdb/common/util_trusts.c +++ b/source4/dsdb/common/util_trusts.c @@ -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. */