Blame SOURCES/0022-Ticket-48894-harden-valueset_array_to_sorted_quick-v.patch

96373c
From dba89dd23d2d62686de192e0986eba65270a62c7 Mon Sep 17 00:00:00 2001
40cd75
From: Mark Reynolds <mreynolds@redhat.com>
40cd75
Date: Thu, 26 Oct 2017 10:03:39 -0400
40cd75
Subject: [PATCH] Ticket 48894 - harden valueset_array_to_sorted_quick valueset
40cd75
  access
40cd75
40cd75
Description:  It's possible during the sorting of a valueset to access an
40cd75
              array element past the allocated size, and also go below the index 0.
40cd75
40cd75
https://pagure.io/389-ds-base/issue/48894
40cd75
40cd75
Reviewed by: nweiderm (Thanks!)
40cd75
40cd75
(cherry picked from commit 2086d052e338ddcbcf6bd3222617991641573a12)
40cd75
---
40cd75
 ldap/servers/slapd/valueset.c | 4 ++--
40cd75
 1 file changed, 2 insertions(+), 2 deletions(-)
40cd75
40cd75
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
96373c
index dc0360738..14ebc48e6 100644
40cd75
--- a/ldap/servers/slapd/valueset.c
40cd75
+++ b/ldap/servers/slapd/valueset.c
96373c
@@ -1019,11 +1019,11 @@ valueset_array_to_sorted_quick(const Slapi_Attr *a, Slapi_ValueSet *vs, size_t l
40cd75
     while (1) {
40cd75
         do {
40cd75
             i++;
96373c
-        } while (valueset_value_cmp(a, vs->va[vs->sorted[i]], vs->va[pivot]) < 0);
40cd75
+        } while (i < vs->max && valueset_value_cmp(a, vs->va[vs->sorted[i]], vs->va[pivot]) < 0);
40cd75
 
40cd75
         do {
40cd75
             j--;
96373c
-        } while (valueset_value_cmp(a, vs->va[vs->sorted[j]], vs->va[pivot]) > 0);
40cd75
+        } while (valueset_value_cmp(a, vs->va[vs->sorted[j]], vs->va[pivot]) > 0 && j > 0);
40cd75
 
40cd75
         if (i >= j) {
40cd75
             break;
40cd75
-- 
40cd75
2.13.6
40cd75