Blame SOURCES/0089-Ticket-49545-final-substring-extended-filter-search-.patch

6f51e1
From 73dd295434a03be28531cea40fde041ce7bd2d7e Mon Sep 17 00:00:00 2001
6f51e1
From: Mark Reynolds <mreynolds@redhat.com>
6f51e1
Date: Tue, 13 Feb 2018 10:35:35 -0500
6f51e1
Subject: [PATCH] Ticket 49545 - final substring extended filter search returns
6f51e1
  invalid result
6f51e1
6f51e1
Bug Description:
6f51e1
	During a search (using extended filter with final substring), the server
6f51e1
	checks the filter before returning the matching entries.
6f51e1
	When checking the attribute value against the filter, it
6f51e1
	uses the wrong value.
6f51e1
6f51e1
Fix Description:
6f51e1
	Make suree it uses the right portion of the attribute value, in order
6f51e1
	to generate the keys to compare.
6f51e1
6f51e1
https://pagure.io/389-ds-base/issue/49545
6f51e1
6f51e1
Reviewed by: Ludwig Krispenz
6f51e1
---
6f51e1
 ldap/servers/plugins/collation/orfilter.c | 20 ++++++++++++++++++--
6f51e1
 1 file changed, 18 insertions(+), 2 deletions(-)
6f51e1
6f51e1
diff --git a/ldap/servers/plugins/collation/orfilter.c b/ldap/servers/plugins/collation/orfilter.c
6f51e1
index 866936afe..8f10f81b6 100644
6f51e1
--- a/ldap/servers/plugins/collation/orfilter.c
6f51e1
+++ b/ldap/servers/plugins/collation/orfilter.c
6f51e1
@@ -180,17 +180,33 @@ ss_filter_match (or_filter_t* or, struct berval** vals)
6f51e1
 	    } else {		/* final */
6f51e1
 		auto size_t attempts = MAX_CHAR_COMBINING;
6f51e1
 		auto char* limit = v.bv_val;
6f51e1
+                auto char *end;
6f51e1
 		auto struct berval** vkeys;
6f51e1
 		auto struct berval* vals[2];
6f51e1
 		auto struct berval key;
6f51e1
+
6f51e1
 		rc = -1;
6f51e1
 		vals[0] = &v;
6f51e1
 		vals[1] = NULL;
6f51e1
 		key.bv_val = (*k)->bv_val;
6f51e1
 		key.bv_len = (*k)->bv_len - 1;
6f51e1
-		v.bv_val = (*vals)->bv_val + (*vals)->bv_len;
6f51e1
+                /* In the following lines it will loop to find
6f51e1
+                 * if the end of the attribute value matches the 'final' of the filter
6f51e1
+                 * Short summary:
6f51e1
+                 * vals contains the attribute value :for example "hello world"
6f51e1
+                 * key contain the key generated from the indexing of final part of the filter.
6f51e1
+                 * for example filter=(<attribut>=*ld), so key contains the indexing("ld").
6f51e1
+                 * 
6f51e1
+                 * The loop will iterate over the attribute value (vals) from the end of string
6f51e1
+                 * to the begining. So it will try to index('d'), index('ld'), index('rld'), index('orld')...
6f51e1
+                 * 
6f51e1
+                 * At each iteration if the key generated from indexing the portion of vals, matches 
6f51e1
+                 * the key generate from the final part of the filter, then the loop stops => we are done
6f51e1
+                 */
6f51e1
+                end = v.bv_val + v.bv_len - 1;
6f51e1
+                v.bv_val = end;
6f51e1
 		while(1) {
6f51e1
-		    v.bv_len = (*vals)->bv_len - (v.bv_val - (*vals)->bv_val);
6f51e1
+                    v.bv_len = end - v.bv_val + 1;
6f51e1
 		    vkeys = ix->ix_index (ix, vals, NULL);
6f51e1
 		    if (vkeys && vkeys[0]) {
6f51e1
 			auto const struct berval* vkey = vkeys[0];
6f51e1
-- 
6f51e1
2.13.6
6f51e1