Blame SOURCES/0015-Issue-5418-Sync_repl-may-crash-while-managing-invali.patch

a77461
From 48ef747b731b5debfefc20757f3b3775828504c2 Mon Sep 17 00:00:00 2001
a77461
From: tbordaz <tbordaz@redhat.com>
a77461
Date: Thu, 18 Aug 2022 11:17:30 +0200
a77461
Subject: [PATCH 3/4] Issue 5418 - Sync_repl may crash while managing invalid
a77461
 cookie (#5420)
a77461
a77461
Bug description:
a77461
	If the servers receives an invalid cookie without separator '#',
a77461
	it parses it into an empty cookie (Sync_Cookie) instead of a NULL
a77461
	cookie (failure).
a77461
	Later it sigsegv when using the empty cookie.
a77461
a77461
Fix description:
a77461
	If the parsing fails return NULL
a77461
a77461
relates: #5418
a77461
a77461
Reviewed by: Viktor Ashirov, Mark Reynolds, William Brown, Simon
a77461
 Pichugin (thanks !)
a77461
---
a77461
 .../suites/syncrepl_plugin/basic_test.py      | 76 +++++++++++++++++++
a77461
 1 file changed, 76 insertions(+)
a77461
a77461
diff --git a/dirsrvtests/tests/suites/syncrepl_plugin/basic_test.py b/dirsrvtests/tests/suites/syncrepl_plugin/basic_test.py
a77461
index 533460e8f..375517693 100644
a77461
--- a/dirsrvtests/tests/suites/syncrepl_plugin/basic_test.py
a77461
+++ b/dirsrvtests/tests/suites/syncrepl_plugin/basic_test.py
a77461
@@ -594,3 +594,79 @@ def test_sync_repl_cenotaph(topo_m2, request):
a77461
                 pass
a77461
 
a77461
     request.addfinalizer(fin)
a77461
+
a77461
+def test_sync_repl_invalid_cookie(topology, request):
a77461
+    """Test sync_repl with invalid cookie
a77461
+
a77461
+    :id: 8fa4a8f8-acf4-42a5-90f1-6ba1d8080e46
a77461
+    :setup: install a standalone instance
a77461
+    :steps:
a77461
+        1. reset instance to standard (no retroCL, no sync_repl, no dynamic plugin)
a77461
+        2. Enable retroCL/content_sync
a77461
+        3. Establish a sync_repl connection
a77461
+        4. Tests servers results to search with invalid cookie
a77461
+        5. Add/delete an user entry to check the server is up and running
a77461
+    :expectedresults:
a77461
+        1. Should succeeds
a77461
+        2. Should succeeds
a77461
+        3. Should succeeds
a77461
+        4. Should succeeds
a77461
+        5. Should succeeds
a77461
+    """
a77461
+
a77461
+    # Reset the instance in a default config
a77461
+    # Disable content sync plugin
a77461
+    topology.standalone.restart()
a77461
+    topology.standalone.plugins.disable(name=PLUGIN_REPL_SYNC)
a77461
+
a77461
+    # Disable retro changelog
a77461
+    topology.standalone.plugins.disable(name=PLUGIN_RETRO_CHANGELOG)
a77461
+
a77461
+    # Disable dynamic plugins
a77461
+    topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-dynamic-plugins', b'off')])
a77461
+    topology.standalone.restart()
a77461
+
a77461
+    # Enable retro changelog
a77461
+    topology.standalone.plugins.enable(name=PLUGIN_RETRO_CHANGELOG)
a77461
+
a77461
+    # Enbale content sync plugin
a77461
+    topology.standalone.plugins.enable(name=PLUGIN_REPL_SYNC)
a77461
+    topology.standalone.restart()
a77461
+
a77461
+    # Setup the syncer
a77461
+    sync = ISyncRepl(topology.standalone)
a77461
+
a77461
+    # Test invalid cookies
a77461
+    cookies = ('#', '##', 'a#a#a', 'a#a#1', 'foo')
a77461
+    for invalid_cookie in cookies:
a77461
+        log.info('Testing cookie: %s' % invalid_cookie)
a77461
+        try:
a77461
+            ldap_search = sync.syncrepl_search(base=DEFAULT_SUFFIX,
a77461
+                                               scope=ldap.SCOPE_SUBTREE,
a77461
+                                               attrlist=['objectclass', 'cn', 'homedirectory', 'sn','uid'],
a77461
+                                               filterstr='(|(objectClass=groupofnames)(objectClass=person))',
a77461
+                                               mode='refreshOnly',
a77461
+                                               cookie=invalid_cookie)
a77461
+            poll_result = sync.syncrepl_poll(all=1)
a77461
+
a77461
+            log.fatal('Invalid cookie accepted!')
a77461
+            assert False
a77461
+        except Exception as e:
a77461
+            log.info('Invalid cookie correctly rejected: {}'.format(e.args[0]['info']))
a77461
+            pass
a77461
+
a77461
+    # check that the server is still up and running
a77461
+    users = UserAccounts(topology.standalone, DEFAULT_SUFFIX)
a77461
+    user = users.create_test_user(uid=1000)
a77461
+
a77461
+    # Success
a77461
+    log.info('Test complete')
a77461
+
a77461
+    def fin():
a77461
+        topology.standalone.restart()
a77461
+        try:
a77461
+            user.delete()
a77461
+        except:
a77461
+            pass
a77461
+
a77461
+    request.addfinalizer(fin)
a77461
-- 
a77461
2.37.1
a77461