diff --git a/SOURCES/0004-Use-already-implemented-clear-for-COMPS-HSList-RhBug-1888343.patch b/SOURCES/0004-Use-already-implemented-clear-for-COMPS-HSList-RhBug-1888343.patch new file mode 100644 index 0000000..d4d5966 --- /dev/null +++ b/SOURCES/0004-Use-already-implemented-clear-for-COMPS-HSList-RhBug-1888343.patch @@ -0,0 +1,68 @@ +From 810efc113dc90a60689295ea99de61eee918c46f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= +Date: Thu, 22 Oct 2020 13:23:25 +0200 +Subject: [PATCH] Use already implemented clear for COMPS_HSList + (RhBug:1888343) + +Instead of reimplementing clear for COMPS_HSList use comps_hslist_clear. +The crash was caused by dangling pointers first and last in the +COMPS_HSList (rt->subnodes) struct, function comps_hslist_clear clears +them out properly. + += changelog = +msg: Fix a crash when clearing COMPS_ObjRTree +type: bugfix +resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1888343 +--- + libcomps/src/comps_objradix.c | 15 ++------------- + libcomps/src/python/tests/__test.py | 10 ++++++++++ + 2 files changed, 12 insertions(+), 13 deletions(-) + +diff --git a/libcomps/src/comps_objradix.c b/libcomps/src/comps_objradix.c +index 840592a..111ddbc 100644 +--- a/libcomps/src/comps_objradix.c ++++ b/libcomps/src/comps_objradix.c +@@ -611,20 +611,9 @@ void comps_objrtree_unset(COMPS_ObjRTree * rt, const char * key) { + } + + void comps_objrtree_clear(COMPS_ObjRTree * rt) { +- COMPS_HSListItem *it, *oldit; + if (rt==NULL) return; +- if (rt->subnodes == NULL) return; +- oldit = rt->subnodes->first; +- it = (oldit)?oldit->next:NULL; +- for (;it != NULL; it=it->next) { +- comps_object_destroy(oldit->data); +- free(oldit); +- oldit = it; +- } +- if (oldit) { +- comps_object_destroy(oldit->data); +- free(oldit); +- } ++ comps_hslist_clear(rt->subnodes); ++ rt->len = 0; + } + + inline COMPS_HSList* __comps_objrtree_all(COMPS_ObjRTree * rt, char keyvalpair) { +diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py +index 9cb957a..2b321e3 100644 +--- a/libcomps/src/python/tests/__test.py ++++ b/libcomps/src/python/tests/__test.py +@@ -986,6 +986,16 @@ def test_envs(self): + + _f([x.name for x in env.option_ids], option_ids) + ++ #@unittest.skip("") ++ def test_clear_for_COMPS_ObjRTree_such_as_group_or_category_namy_by_lang(self): ++ comps = libcomps.Comps() ++ ret = comps.fromxml_f("comps/f21-rawhide-comps.xml") ++ ++ env = comps.categories[0].name_by_lang.clear() ++ env = comps.groups[0].name_by_lang.clear() ++ ++ self.assertEqual(str(comps.categories[0].name_by_lang), u'{}') ++ self.assertEqual(str(comps.groups[0].name_by_lang), u'{}') + + #@unittest.skip("") + def test_xml_options(self): diff --git a/SPECS/libcomps.spec b/SPECS/libcomps.spec index 856a014..0356d29 100644 --- a/SPECS/libcomps.spec +++ b/SPECS/libcomps.spec @@ -14,7 +14,7 @@ Name: libcomps Version: 0.1.11 -Release: 4%{?dist} +Release: 5%{?dist} Summary: Comps XML file manipulation library License: GPLv2+ @@ -23,6 +23,7 @@ Source0: %{url}/archive/%{name}-%{version}/%{name}-%{version}.tar.gz Patch0: 0001-Fix-order-of-asserts-in-unit-test-RhBug1713220.patch Patch1: 0002-Empty-dict-created-by-_by_lang-in-python-api-causes-segfault.patch Patch2: 0003-Do-not-skip-type-mandatory-in-xml-output-and-test-it-RhBu1771224.patch +Patch3: 0004-Use-already-implemented-clear-for-COMPS-HSList-RhBug-1888343.patch BuildRequires: gcc-c++ BuildRequires: cmake @@ -192,6 +193,9 @@ popd %endif %changelog +* Thu Jan 14 2021 Nicola Sella - 0.1.11-5 +- Use already implemented clear for COMPS_HSList (RhBug:1888343) + * Mon Jan 13 2020 Ales Matej - 0.1.11-4 - Do not skip type=mandatory in xml output (RhBug:1771224)