From 4fa67dee9a83f0e48e698f990e045395aa734767 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Fri, 23 Aug 2024 10:17:17 +1200 Subject: [PATCH] ldb:dn_compare: be a bit more transitive If neither dn can casefold, they should be considered equal. Otherwise cmp(dn1, dn2) will be inconsistent with cmp(dn2, dn1). These will still sort to the end of the list, relative to any valid DNs. Signed-off-by: Douglas Bagnall Reviewed-by: Andreas Schneider --- lib/ldb/common/ldb_dn.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ldb/common/ldb_dn.c b/lib/ldb/common/ldb_dn.c index 8e89571229f..16de79db552 100644 --- a/lib/ldb/common/ldb_dn.c +++ b/lib/ldb/common/ldb_dn.c @@ -1171,6 +1171,7 @@ int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1) } if (( ! dn0->valid_case) || ( ! dn1->valid_case)) { + bool ok0, ok1; if (dn0->linearized && dn1->linearized) { /* try with a normal compare first, if we are lucky * we will avoid exploding and casefolding */ @@ -1178,15 +1179,20 @@ int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1) return 0; } } - - if ( ! ldb_dn_casefold_internal(dn0)) { + /* + * If a DN can't casefold, it goes to the end. + */ + ok0 = ldb_dn_casefold_internal(dn0); + ok1 = ldb_dn_casefold_internal(dn1); + if (! ok0) { + if (! ok1) { + return 0; + } return 1; } - - if ( ! ldb_dn_casefold_internal(dn1)) { + if (! ok1) { return -1; } - } /* -- 2.47.3