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

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