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

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