From 5805f99acd0154ac41425d524ad862881d7b350c Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 12 Mar 2023 23:13:22 +0000 Subject: [PATCH] Test calling dc_context_unref() during dc_configure() dc_configure() spawns a background configuration process. It should increase the number of context references so even if we unref the context, it is not dropped until the end of the configuration process. Currently running the test with `pytest tests/test_1_online.py::test_configure_unref` results in segmentation fault. --- python/tests/test_1_online.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index 7f62dcefd..d1761f02e 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -72,6 +72,19 @@ def test_configure_canceled(acfactory): pass +def test_configure_unref(tmpdir): + """Test that removing the last reference to the context during ongoing configuration + does not result in use-after-free.""" + from deltachat.capi import ffi, lib + + path = tmpdir.mkdir("test_configure_unref").join("dc.db").strpath + dc_context = lib.dc_context_new(ffi.NULL, path.encode("utf8"), ffi.NULL) + lib.dc_set_config(dc_context, "addr".encode("utf8"), "foo@x.testrun.org".encode("utf8")) + lib.dc_set_config(dc_context, "mail_pw".encode("utf8"), "abc".encode("utf8")) + lib.dc_configure(dc_context) + lib.dc_context_unref(dc_context) + + def test_export_import_self_keys(acfactory, tmpdir, lp): ac1, ac2 = acfactory.get_online_accounts(2)