diff --git a/SOURCES/0001-Fix-order-of-asserts-in-unit-test-RhBug1713220.patch b/SOURCES/0001-Fix-order-of-asserts-in-unit-test-RhBug1713220.patch new file mode 100644 index 0000000..20e98f7 --- /dev/null +++ b/SOURCES/0001-Fix-order-of-asserts-in-unit-test-RhBug1713220.patch @@ -0,0 +1,26 @@ +From 849ae4a7c7abe72baaeb22214be3e04e4e43eb81 Mon Sep 17 00:00:00 2001 +From: Jaroslav Rohel +Date: Wed, 22 May 2019 13:21:19 +0200 +Subject: [PATCH] Fix: order of asserts() in unit test (RhBug:1713220) + +--- + libcomps/src/python/tests/__test.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py +index 40c2e83..c9b4dd4 100644 +--- a/libcomps/src/python/tests/__test.py ++++ b/libcomps/src/python/tests/__test.py +@@ -891,8 +891,8 @@ class COMPSTest(unittest.TestCase): + gid1 = libcomps.GroupId("gid1") + gid2 = libcomps.GroupId("gid2", default=False) + gid3 = libcomps.GroupId("gid3", default=True) +- self.assertRaises(TypeError, gid1.__eq__, 1) + self.assertTrue(gid1 != None) ++ self.assertRaises(TypeError, gid1.__eq__, 1) + self.assertTrue(gid1 == gid1) + self.assertTrue(gid1 != "gid2") + self.assertTrue(gid1 != gid2) +-- +libgit2 0.28.2 + diff --git a/SOURCES/0002-Empty-dict-created-by-_by_lang-in-python-api-causes-segfault.patch b/SOURCES/0002-Empty-dict-created-by-_by_lang-in-python-api-causes-segfault.patch new file mode 100644 index 0000000..3e4f692 --- /dev/null +++ b/SOURCES/0002-Empty-dict-created-by-_by_lang-in-python-api-causes-segfault.patch @@ -0,0 +1,161 @@ +From 257df5670310775a9c279f5f34e3d088966759b1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= +Date: Mon, 7 Oct 2019 12:14:22 +0200 +Subject: [PATCH 1/3] Update couple of tests + +- list indices cannot by of type float +- remove unnecessary print +- update print with parenthesis which are now required in python +--- + libcomps/src/python/tests/__test.py | 2 +- + libcomps/src/python/tests/test_libcomps.py | 1 - + libcomps/src/python/tests/test_merge_comps.py | 4 ++-- + 3 files changed, 3 insertions(+), 4 deletions(-) + +diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py +index c9b4dd4..c7529f3 100644 +--- a/libcomps/src/python/tests/__test.py ++++ b/libcomps/src/python/tests/__test.py +@@ -225,7 +225,7 @@ def test_union3(self): + def test_hash(self): + s = set() + for x in range(6): +- s.add(self.obj_constructor(**self.obj_data[x/2])) ++ s.add(self.obj_constructor(**self.obj_data[int(x/2)])) + self.assertTrue(len(s) == 3) + self.assertTrue(hash(self.obj_constructor(**self.obj_data[0])) ==\ + hash(self.obj_constructor(**self.obj_data[0]))) +diff --git a/libcomps/src/python/tests/test_libcomps.py b/libcomps/src/python/tests/test_libcomps.py +index 2a18984..71311ef 100755 +--- a/libcomps/src/python/tests/test_libcomps.py ++++ b/libcomps/src/python/tests/test_libcomps.py +@@ -19,7 +19,6 @@ + class TestLibcomps(unittest.TestCase): + + def setUp(self): +- print (dir(libcomps)) + self.comps = libcomps.Comps() + self.comps.fromxml_f("comps/comps-f21.xml") + self.tmp_dir = tempfile.mkdtemp() +diff --git a/libcomps/src/python/tests/test_merge_comps.py b/libcomps/src/python/tests/test_merge_comps.py +index beef2cf..73e743f 100755 +--- a/libcomps/src/python/tests/test_merge_comps.py ++++ b/libcomps/src/python/tests/test_merge_comps.py +@@ -7,10 +7,10 @@ + + try: + import _libpycomps as libcomps +- print "local tests" ++ print("local tests") + except ImportError: + import libcomps +- print "global tests" ++ print("global tests") + + + class TestMergeComps(unittest.TestCase): + +From 1b7add27595b12b9f47e54c3e5f1bda2177da346 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= +Date: Mon, 7 Oct 2019 12:50:21 +0200 +Subject: [PATCH 2/3] Fix segfault when converting empty dict to string + (RhBug:1757959) + +Handle all elements in single loop consistently, instead of handling +last element separately which caused problems with empty dictionary. + +https://bugzilla.redhat.com/show_bug.cgi?id=1757959 +--- + libcomps/src/python/src/pycomps_dict.c | 20 +------------------- + 1 file changed, 1 insertion(+), 19 deletions(-) + +diff --git a/libcomps/src/python/src/pycomps_dict.c b/libcomps/src/python/src/pycomps_dict.c +index 1b42909..4a20cf7 100644 +--- a/libcomps/src/python/src/pycomps_dict.c ++++ b/libcomps/src/python/src/pycomps_dict.c +@@ -78,7 +78,7 @@ PyObject* PyCOMPSDict_str(PyObject *self) { + pairlist = comps_objdict_pairs(((PyCOMPS_Dict*)self)->dict); + char *tmpstr; + +- for (it = pairlist->first; it != pairlist->last; it = it->next) { ++ for (it = pairlist->first; it != NULL; it = it->next) { + tmp = ret; + tmpkey = __pycomps_lang_decode(((COMPS_ObjRTreePair*)it->data)->key); + if (!tmpkey) { +@@ -99,24 +99,6 @@ PyObject* PyCOMPSDict_str(PyObject *self) { + Py_XDECREF(tmpkey); + Py_XDECREF(tmpval); + } +- tmp = ret; +- tmpkey = __pycomps_lang_decode(((COMPS_RTreePair*)it->data)->key); +- if (!tmpkey) { +- goto out; +- } +- tmpstr = comps_object_tostr(((COMPS_ObjRTreePair*)it->data)->data); +- tmpval = __pycomps_lang_decode(tmpstr); +- free(tmpstr); +- if (!tmpval) { +- //PyErr_SetString(PyExc_TypeError, "val convert error"); +- goto out; +- } +- tmp2 = PyUnicode_FromFormat("%U = '%U'", tmpkey, tmpval); +- ret = PyUnicode_Concat(ret, tmp2); +- Py_XDECREF(tmp); +- Py_XDECREF(tmp2); +- Py_XDECREF(tmpkey); +- Py_XDECREF(tmpval); + + tmp = ret; + tmp2 = PyUnicode_FromString("}"); + +From 6b4bffb541e70a1715e91ba06de8172b57cd26f0 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= +Date: Mon, 7 Oct 2019 12:52:59 +0200 +Subject: [PATCH 3/3] Add test for python API with empty *_by_lang dictionary + input + +--- + .../python/tests/comps/comps_empty_by_lang_tags.xml | 12 ++++++++++++ + libcomps/src/python/tests/test_libcomps.py | 10 ++++++++++ + 2 files changed, 22 insertions(+) + create mode 100644 libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml + +diff --git a/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml b/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml +new file mode 100644 +index 0000000..2f40a86 +--- /dev/null ++++ b/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml +@@ -0,0 +1,12 @@ ++ ++ ++ ++ ++ birds ++ ++ ++ ++ all ++ all ++ ++ +diff --git a/libcomps/src/python/tests/test_libcomps.py b/libcomps/src/python/tests/test_libcomps.py +index 71311ef..64c2b59 100755 +--- a/libcomps/src/python/tests/test_libcomps.py ++++ b/libcomps/src/python/tests/test_libcomps.py +@@ -153,6 +153,16 @@ def test_duplicate_groups(self): + #print self.comps.xml_str() + self.comps.fromxml_str(self.comps.xml_str()) + ++ def test_empty_by_lang_tags(self): ++ self.comps = libcomps.Comps() ++ self.comps.fromxml_f("comps/comps_empty_by_lang_tags.xml") ++ for group in self.comps.groups: ++ self.assertEqual("{}", str(group.name_by_lang)) ++ self.assertEqual("{}", str(group.desc_by_lang)) ++ ++ for category in self.comps.categories: ++ self.assertEqual("{}", str(category.name_by_lang)) ++ self.assertEqual("{}", str(category.desc_by_lang)) + + if __name__ == "__main__": + unittest.main(testRunner = utest.MyRunner) diff --git a/SPECS/libcomps.spec b/SPECS/libcomps.spec index 68e6290..f2d6496 100644 --- a/SPECS/libcomps.spec +++ b/SPECS/libcomps.spec @@ -14,12 +14,14 @@ Name: libcomps Version: 0.1.11 -Release: 1%{?dist} +Release: 3%{?dist} Summary: Comps XML file manipulation library License: GPLv2+ URL: https://github.com/rpm-software-management/libcomps 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 BuildRequires: gcc-c++ BuildRequires: cmake @@ -189,6 +191,12 @@ popd %endif %changelog +* Wed Nov 13 2019 Ales Matej - 0.1.11-3 +- Fix segfault caused by empty dict created by *_by_lang in python api (RhBug:1757959) + +* Thu Aug 01 2019 Pavla Kratochvilova - 0.1.11-2 +- Backport patch: Fix order of asserts in unit test (RhBug:1713220) + * Mon May 13 2019 Pavla Kratochvilova - 0.1.11-1 - Update to 0.1.11