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

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