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

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