#49898 Ticket 49890 : ldapsearch with server side sort crashes the
Closed 4 years ago by spichugi. Opened 6 years ago by mreynolds.
mreynolds/389-ds-base ticket49890  into  master

@@ -0,0 +1,59 @@ 

+ import logging

+ import pytest

+ import os

+ import ldap

+ from lib389.dbgen import dbgen

+ from lib389._constants import *

+ from lib389.topologies import topology_st as topo

+ from lib389._controls import SSSRequestControl

+ 

+ DEBUGGING = os.getenv("DEBUGGING", default=False)

+ if DEBUGGING:

+     logging.getLogger(__name__).setLevel(logging.DEBUG)

+ else:

+     logging.getLogger(__name__).setLevel(logging.INFO)

+ log = logging.getLogger(__name__)

+ 

+ 

+ def test_sss_mr(topo):

+     """Test matching rule/server side sort does not crash DS

+ 

+     :id: 48c73d76-1694-420f-ab55-187135f2d260

+     :setup: Standalone Instance

+     :steps:

+         1. Add sample entries to the database

+         2. Perform search using server side control (uid:2.5.13.3)

+     :expectedresults:

+         1. Success

+         2. Success

+     """

+ 

+     log.info("Creating LDIF...")

+     ldif_dir = topo.standalone.get_ldif_dir()

+     ldif_file = os.path.join(ldif_dir, 'mr-crash.ldif')

+     dbgen(topo.standalone, 5, ldif_file, DEFAULT_SUFFIX)

+ 

+     log.info("Importing LDIF...")

+     topo.standalone.stop()

+     assert topo.standalone.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file)

+     topo.standalone.start()

+ 

+     log.info('Search using server side sorting using undefined mr in the attr...')

+     sort_ctrl = SSSRequestControl(True, ['uid:2.5.13.3'])

+     controls = [sort_ctrl]

+     msg_id = topo.standalone.search_ext(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,

+                                         "objectclass=*", serverctrls=controls)

+     try:

+         rtype, rdata, rmsgid, response_ctrl = topo.standalone.result3(msg_id)

+     except ldap.OPERATIONS_ERROR:

+         pass

+ 

+     log.info("Test PASSED")

+ 

+ 

+ if __name__ == '__main__':

+     # Run isolated

+     # -s for DEBUG mode

+     CURRENT_FILE = os.path.realpath(__file__)

+     pytest.main(["-s", CURRENT_FILE])

+ 

@@ -546,6 +546,16 @@ 

              /* Now copy it, so the second call doesn't crap on it */

              value_a = slapi_ch_bvecdup(temp_value); /* Really, we'd prefer to not call the chXXX variant...*/

              matchrule_values_to_keys(this_one->mr_pb, actual_value_b, &value_b);

+ 

+             if ((actual_value_a && !value_a) ||

+                 (actual_value_b && !value_b)) {

+                 ber_bvecfree(actual_value_a);

+                 ber_bvecfree(actual_value_b);

+                 CACHE_RETURN(&inst->inst_cache, &a);

+                 CACHE_RETURN(&inst->inst_cache, &b);

+                 *error = 1;

+                 return 0;

+             }

              if (actual_value_a)

                  ber_bvecfree(actual_value_a);

              if (actual_value_b)
@@ -717,6 +727,8 @@ 

                 A[i] >= A[lo] for higuy <= i <= hi */

  

              do {

+                 if (error)

+                     return LDAP_OPERATIONS_ERROR;

                  loguy++;

              } while (loguy <= hi && compare_entries_sv(loguy, lo, s, bc, &error) <= 0);

  
@@ -724,6 +736,8 @@ 

                 either loguy > hi or A[loguy] > A[lo] */

  

              do {

+                 if (error)

+                     return LDAP_OPERATIONS_ERROR;

                  higuy--;

              } while (higuy > lo && compare_entries_sv(higuy, lo, s, bc, &error) >= 0);

  

ldap server

Bug Description:
Server side sort with a specified matching rule trigger a crash

Fix Description:
Check if the we are able to index the provided value.
If we are not then slapd_qsort returns an error (LDAP_OPERATION_ERROR)

https://pagure.io/389-ds-base/issue/49890

Reviewed by: mreynolds

Platforms tested: F27

Flag Day: no

Doc impact: no

Pull-Request has been merged by mreynolds

6 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/2957

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

4 years ago