Skip to content

Commit

Permalink
Issue 5332 - BUG - normalise filter as intended
Browse files Browse the repository at this point in the history
Bug Description: Due to a mistake in the optimiser rework
the filter as intended was not normalised, causing some searches
to fail

Fix Description: Always normalise both filters.

fixes: 389ds#5332

Author: William Brown <william@blackhats.net.au>

Review by: ???
  • Loading branch information
Firstyear committed Jun 10, 2022
1 parent cd18e41 commit 2b669f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions ldap/servers/slapd/back-ldbm/back-ldbm.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ typedef struct _back_search_result_set
int sr_flags; /* Magic flags, defined below */
int sr_current_sizelimit; /* Current sizelimit */
Slapi_Filter *sr_norm_filter; /* search filter pre-normalized */
Slapi_Filter *sr_norm_filter_intent; /* intended search filter pre-normalized */
} back_search_result_set;
#define SR_FLAG_MUST_APPLY_FILTER_TEST 1 /* If set in sr_flags, means that we MUST apply the filter test */

Expand Down
19 changes: 18 additions & 1 deletion ldap/servers/slapd/back-ldbm/ldbm_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,22 +933,34 @@ ldbm_back_search(Slapi_PBlock *pb)
li->li_filter_bypass_check) {
int rc = 0, filt_errs = 0;
Slapi_Filter *filter = NULL;
Slapi_Filter *filter_intent = NULL;

slapi_log_err(SLAPI_LOG_FILTER, "ldbm_back_search", "Applying Filter Test\n");

slapi_pblock_get(pb, SLAPI_SEARCH_FILTER, &filter);
slapi_pblock_get(pb, SLAPI_SEARCH_FILTER_INTENDED, &filter_intent);
if (NULL == filter) {
tmp_err = LDAP_OPERATIONS_ERROR;
tmp_desc = "Filter is not set";
goto bail;
}
slapi_filter_free(sr->sr_norm_filter, 1);
sr->sr_norm_filter = slapi_filter_dup(filter);

/* step 1 - normalize all of the values used in the search filter */
slapi_filter_normalize(sr->sr_norm_filter, PR_TRUE /* normalize values too */);
/* step 2 - pre-compile the substr regex and the equality flags */
rc = slapi_filter_apply(sr->sr_norm_filter, ldbm_search_compile_filter,
NULL, &filt_errs);

if (rc == SLAPI_FILTER_SCAN_NOMORE && filter_intent) {
slapi_filter_free(sr->sr_norm_filter_intent, 1);
sr->sr_norm_filter_intent = slapi_filter_dup(filter_intent);
slapi_filter_normalize(sr->sr_norm_filter_intent, PR_TRUE /* normalize values too */);
rc = slapi_filter_apply(sr->sr_norm_filter_intent, ldbm_search_compile_filter,
NULL, &filt_errs);
}

if (rc != SLAPI_FILTER_SCAN_NOMORE) {
slapi_log_err(SLAPI_LOG_ERR,
"ldbm_back_search", "Could not pre-compile the search filter - error %d %d\n",
Expand Down Expand Up @@ -1468,10 +1480,15 @@ ldbm_back_next_search_entry(Slapi_PBlock *pb)

if (sr->sr_norm_filter) {
int val = 1;
slapi_pblock_set(pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &val);
filter = sr->sr_norm_filter;
}

if (sr->sr_norm_filter_intent) {
int val = 1;
slapi_pblock_set(pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &val);
filter_intent = sr->sr_norm_filter_intent;
}

if (op_is_pagedresults(op)) {
int myslimit;
/* On Simple Paged Results search, sizelimit is appied for each page. */
Expand Down

0 comments on commit 2b669f1

Please sign in to comment.