From 4f38415e7df2e2e5f0eb675eb5778b34173e29ce Mon Sep 17 00:00:00 2001 From: Jan Kolarik Date: Tue, 10 Dec 2024 13:06:29 +0000 Subject: [PATCH] conf: Test for segfaulting iterator in ConfigParser This is a follow-up to https://github.com/rpm-software-management/libdnf/pull/1682. Reported bug: https://bugzilla.redhat.com/show_bug.cgi?id=2330562 --- tests/conf/test_parser.py | 14 ++++++++++++++ tests/etc/empty.conf | 1 + 2 files changed, 15 insertions(+) create mode 100644 tests/etc/empty.conf diff --git a/tests/conf/test_parser.py b/tests/conf/test_parser.py index ad0d61e318..2797395855 100644 --- a/tests/conf/test_parser.py +++ b/tests/conf/test_parser.py @@ -66,3 +66,17 @@ def test_empty_option(self): conf.config_file_path = FN conf.read() self.assertEqual(conf.reposdir, '') + + def test_iterator_segfault(self): + # https://bugzilla.redhat.com/show_bug.cgi?id=2330562 + empty_conf_path = tests.support.resource_path('etc/empty.conf') + + parser = ConfigParser() + parser.read(empty_conf_path) + self.assertTrue(parser.hasSection("main")) + + sectObj = parser.getData()["main"] + [item for item in sectObj] + + # this should not segfault + [item for item in iter(sectObj)] diff --git a/tests/etc/empty.conf b/tests/etc/empty.conf new file mode 100644 index 0000000000..9280d27d75 --- /dev/null +++ b/tests/etc/empty.conf @@ -0,0 +1 @@ +[main] \ No newline at end of file