From efa9f173d20a51f3858fca7c36d8f8c692c717e3 Mon Sep 17 00:00:00 2001 From: HAMANO Tsukasa Date: Wed, 26 Jun 2024 10:51:17 +0900 Subject: [PATCH] ITS#10233 - fix idl intersection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `mdb_idl_intersection()` and `wt_idl_intersection()` functions derived from back-bdb return wrong results. expect: [1, 3] ∩ [2] = [] actual: [1, 3] ∩ [2] = [2] also - Add scope checking for back-wt - fix compiler warning --- servers/slapd/back-mdb/idl.c | 4 +++- servers/slapd/back-wt/id2entry.c | 3 ++- servers/slapd/back-wt/idl.c | 11 +++++------ servers/slapd/back-wt/search.c | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/servers/slapd/back-mdb/idl.c b/servers/slapd/back-mdb/idl.c index c433372cc7..6ed2c19f68 100644 --- a/servers/slapd/back-mdb/idl.c +++ b/servers/slapd/back-mdb/idl.c @@ -727,7 +727,9 @@ mdb_idl_intersection( if ( idmin > idmax ) { a[0] = 0; return 0; - } else if ( idmin == idmax ) { + } else if ( idmin == idmax && + (( MDB_IDL_FIRST(a) == MDB_IDL_LAST(b)) || + ( MDB_IDL_FIRST(b) == MDB_IDL_LAST(a)))) { a[0] = 1; a[1] = idmin; return 0; diff --git a/servers/slapd/back-wt/id2entry.c b/servers/slapd/back-wt/id2entry.c index a9bba1837b..558abcee46 100644 --- a/servers/slapd/back-wt/id2entry.c +++ b/servers/slapd/back-wt/id2entry.c @@ -232,7 +232,7 @@ int wt_entry_return( return 0; } - /* Our entries are allocated in two blocks; the data comes from + /* Our entries are allocated in two blocks; the data comes from * the db itself and the Entry structure and associated pointers * are allocated in entry_decode. The db data pointer is saved * in e_bv. @@ -256,6 +256,7 @@ int wt_entry_return( } entry_free( e ); + return 0; } int wt_entry_release( diff --git a/servers/slapd/back-wt/idl.c b/servers/slapd/back-wt/idl.c index c42aa3a07c..7c670f188e 100644 --- a/servers/slapd/back-wt/idl.c +++ b/servers/slapd/back-wt/idl.c @@ -53,13 +53,10 @@ void wt_idl_dump( ID *ids ) } else { ID i; - Debug( LDAP_DEBUG_ANY, "IDL: size %ld", (long) ids[0] ); + Debug( LDAP_DEBUG_ANY, "IDL: size %ld\n", (long) ids[0] ); for( i=1; i<=ids[0]; i++ ) { - if( i % 16 == 1 ) { - Debug( LDAP_DEBUG_ANY, "\n" ); - } - Debug( LDAP_DEBUG_ANY, " %02lx", (long) ids[i] ); + Debug( LDAP_DEBUG_ANY, " %ld\n", (long) ids[i] ); } Debug( LDAP_DEBUG_ANY, "\n" ); @@ -282,7 +279,9 @@ wt_idl_intersection( if ( idmin > idmax ) { a[0] = 0; return 0; - } else if ( idmin == idmax ) { + } else if ( idmin == idmax && + (( WT_IDL_FIRST(a) == WT_IDL_LAST(b)) || + ( WT_IDL_FIRST(b) == WT_IDL_LAST(a)))) { a[0] = 1; a[1] = idmin; return 0; diff --git a/servers/slapd/back-wt/search.c b/servers/slapd/back-wt/search.c index d759b7ca3f..60ebd2b69f 100644 --- a/servers/slapd/back-wt/search.c +++ b/servers/slapd/back-wt/search.c @@ -606,7 +606,7 @@ loop_begin: if ( id == base->e_id ) scopeok = 1; break; case LDAP_SCOPE_ONELEVEL: - scopeok = 1; + scopeok = dnIsSuffixScope(&e->e_nname, &base->e_nname, LDAP_SCOPE_ONELEVEL); break; case LDAP_SCOPE_CHILDREN: if ( id == base->e_id ) break;