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

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