Backport patch to fix crash when dumping updateinfo (RhBug:1707981)

This commit is contained in:
Pavla Kratochvilova 2019-05-17 07:07:50 +02:00
parent 04ff1d7f3f
commit d141b953ab
2 changed files with 240 additions and 1 deletions

View File

@ -0,0 +1,234 @@
From 60ca8fe3db7d2032a815f19a8299a86ee63c5267 Mon Sep 17 00:00:00 2001
From: Aleš Matěj <amatej@redhat.com>
Date: Thu, 9 May 2019 08:48:32 +0200
Subject: [PATCH] Fix crash when dumping updateinfo and module is ommited (RhBug:1707981)
---
src/xml_dump_updateinfo.c | 23 +++++++++++++----------
tests/python/tests/test_updateinfo.py | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 192 insertions(+), 10 deletions(-)
diff --git a/src/xml_dump_updateinfo.c b/src/xml_dump_updateinfo.c
index d5ae96f..fafe686 100644
--- a/src/xml_dump_updateinfo.c
+++ b/src/xml_dump_updateinfo.c
@@ -68,16 +68,19 @@ cr_xml_dump_updatecollectionpackages(xmlNodePtr collection, GSList *packages)
void
cr_xml_dump_updatecollectionmodule(xmlNodePtr collection, cr_UpdateCollectionModule *module)
{
- xmlNodePtr xml_module;
- xml_module = xmlNewChild(collection, NULL, BAD_CAST "module", NULL);
-
- cr_xmlNewProp_c(xml_module, BAD_CAST "name", BAD_CAST module->name);
- cr_xmlNewProp_c(xml_module, BAD_CAST "stream", BAD_CAST module->stream);
- gchar buf[21]; //20 + '\0' is max number of chars of guint64: G_MAXUINT64 (= 18,446,744,073,709,551,615)
- snprintf(buf, 21, "%" G_GUINT64_FORMAT, module->version);
- cr_xmlNewProp_c(xml_module, BAD_CAST "version", BAD_CAST buf);
- cr_xmlNewProp_c(xml_module, BAD_CAST "context", BAD_CAST module->context);
- cr_xmlNewProp_c(xml_module, BAD_CAST "arch", BAD_CAST module->arch);
+ if (!module)
+ return;
+
+ xmlNodePtr xml_module;
+ xml_module = xmlNewChild(collection, NULL, BAD_CAST "module", NULL);
+
+ cr_xmlNewProp_c(xml_module, BAD_CAST "name", BAD_CAST module->name);
+ cr_xmlNewProp_c(xml_module, BAD_CAST "stream", BAD_CAST module->stream);
+ gchar buf[21]; //20 + '\0' is max number of chars of guint64: G_MAXUINT64 (= 18,446,744,073,709,551,615)
+ snprintf(buf, 21, "%" G_GUINT64_FORMAT, module->version);
+ cr_xmlNewProp_c(xml_module, BAD_CAST "version", BAD_CAST buf);
+ cr_xmlNewProp_c(xml_module, BAD_CAST "context", BAD_CAST module->context);
+ cr_xmlNewProp_c(xml_module, BAD_CAST "arch", BAD_CAST module->arch);
}
void
diff --git a/tests/python/tests/test_updateinfo.py b/tests/python/tests/test_updateinfo.py
index e89f1a8..727b707 100644
--- a/tests/python/tests/test_updateinfo.py
+++ b/tests/python/tests/test_updateinfo.py
@@ -210,3 +210,182 @@ class TestCaseUpdateInfo(unittest.TestCase):
</update>
</updates>
""" % {"now": now.strftime("%Y-%m-%d %H:%M:%S")})
+
+ def test_updateinfo_xml_dump_04(self):
+ now = datetime.now()
+ # Microseconds are always 0 in updateinfo
+ now = datetime(now.year, now.month, now.day, now.hour, now.minute,
+ now.second, 0)
+
+ pkg = cr.UpdateCollectionPackage()
+ pkg.name = "foo"
+ pkg.version = "1.2"
+ pkg.release = "3"
+ pkg.epoch = "0"
+ pkg.arch = "x86"
+ pkg.src = "foo.src.rpm"
+ pkg.filename = "foo.rpm"
+ pkg.sum = "abcdef"
+ pkg.sum_type = cr.SHA1
+ pkg.reboot_suggested = True
+
+ # Collection without module
+ col = cr.UpdateCollection()
+ col.shortname = "short name"
+ col.name = "long name"
+ col.append(pkg)
+
+ ref = cr.UpdateReference()
+ ref.href = "href"
+ ref.id = "id"
+ ref.type = "type"
+ ref.title = "title"
+
+ rec = cr.UpdateRecord()
+ rec.fromstr = "from"
+ rec.status = "status"
+ rec.type = "type"
+ rec.version = "version"
+ rec.id = "id"
+ rec.title = "title"
+ rec.issued_date = now
+ rec.updated_date = now
+ rec.rights = "rights"
+ rec.release = "release"
+ rec.pushcount = "pushcount"
+ rec.severity = "severity"
+ rec.summary = "summary"
+ rec.description = "description"
+ rec.solution = "solution"
+ rec.append_collection(col)
+ rec.append_reference(ref)
+
+ ui = cr.UpdateInfo()
+ ui.append(rec)
+
+ xml = ui.xml_dump()
+
+ self.assertEqual(xml,
+"""<?xml version="1.0" encoding="UTF-8"?>
+<updates>
+ <update from="from" status="status" type="type" version="version">
+ <id>id</id>
+ <title>title</title>
+ <issued date="%(now)s"/>
+ <updated date="%(now)s"/>
+ <rights>rights</rights>
+ <release>release</release>
+ <pushcount>pushcount</pushcount>
+ <severity>severity</severity>
+ <summary>summary</summary>
+ <description>description</description>
+ <solution>solution</solution>
+ <references>
+ <reference href="href" id="id" type="type" title="title"/>
+ </references>
+ <pkglist>
+ <collection short="short name">
+ <name>long name</name>
+ <package name="foo" version="1.2" release="3" epoch="0" arch="x86" src="foo.src.rpm">
+ <filename>foo.rpm</filename>
+ <sum type="sha1">abcdef</sum>
+ <reboot_suggested/>
+ </package>
+ </collection>
+ </pkglist>
+ </update>
+</updates>
+""" % {"now": now.strftime("%Y-%m-%d %H:%M:%S")})
+
+ def test_updateinfo_xml_dump_05(self):
+ now = datetime.now()
+ # Microseconds are always 0 in updateinfo
+ now = datetime(now.year, now.month, now.day, now.hour, now.minute,
+ now.second, 0)
+
+ # Collection module with unset fields
+ mod = cr.UpdateCollectionModule()
+ mod.version = 18446744073709551615
+ mod.context = "deadbeef"
+ mod.arch = "x86"
+
+ pkg = cr.UpdateCollectionPackage()
+ pkg.name = "foo"
+ pkg.version = "1.2"
+ pkg.release = "3"
+ pkg.epoch = "0"
+ pkg.arch = "x86"
+ pkg.src = "foo.src.rpm"
+ pkg.filename = "foo.rpm"
+ pkg.sum = "abcdef"
+ pkg.sum_type = cr.SHA1
+ pkg.reboot_suggested = True
+
+ col = cr.UpdateCollection()
+ col.shortname = "short name"
+ col.name = "long name"
+ col.module = mod
+ col.append(pkg)
+
+ ref = cr.UpdateReference()
+ ref.href = "href"
+ ref.id = "id"
+ ref.type = "type"
+ ref.title = "title"
+
+ rec = cr.UpdateRecord()
+ rec.fromstr = "from"
+ rec.status = "status"
+ rec.type = "type"
+ rec.version = "version"
+ rec.id = "id"
+ rec.title = "title"
+ rec.issued_date = now
+ rec.updated_date = now
+ rec.rights = "rights"
+ rec.release = "release"
+ rec.pushcount = "pushcount"
+ rec.severity = "severity"
+ rec.summary = "summary"
+ rec.description = "description"
+ rec.solution = "solution"
+ rec.append_collection(col)
+ rec.append_reference(ref)
+
+ ui = cr.UpdateInfo()
+ ui.append(rec)
+
+ xml = ui.xml_dump()
+
+ self.assertEqual(xml,
+"""<?xml version="1.0" encoding="UTF-8"?>
+<updates>
+ <update from="from" status="status" type="type" version="version">
+ <id>id</id>
+ <title>title</title>
+ <issued date="%(now)s"/>
+ <updated date="%(now)s"/>
+ <rights>rights</rights>
+ <release>release</release>
+ <pushcount>pushcount</pushcount>
+ <severity>severity</severity>
+ <summary>summary</summary>
+ <description>description</description>
+ <solution>solution</solution>
+ <references>
+ <reference href="href" id="id" type="type" title="title"/>
+ </references>
+ <pkglist>
+ <collection short="short name">
+ <name>long name</name>
+ <module version="18446744073709551615" context="deadbeef" arch="x86"/>
+ <package name="foo" version="1.2" release="3" epoch="0" arch="x86" src="foo.src.rpm">
+ <filename>foo.rpm</filename>
+ <sum type="sha1">abcdef</sum>
+ <reboot_suggested/>
+ </package>
+ </collection>
+ </pkglist>
+ </update>
+</updates>
+""" % {"now": now.strftime("%Y-%m-%d %H:%M:%S")})
--
libgit2 0.27.7

View File

@ -34,10 +34,12 @@
Summary: Creates a common metadata repository Summary: Creates a common metadata repository
Name: createrepo_c Name: createrepo_c
Version: 0.13.2 Version: 0.13.2
Release: 1%{?dist} Release: 2%{?dist}
License: GPLv2+ License: GPLv2+
URL: https://github.com/rpm-software-management/createrepo_c URL: https://github.com/rpm-software-management/createrepo_c
Source0: %{url}/archive/%{version}/%{name}-%{version}.tar.gz Source0: %{url}/archive/%{version}/%{name}-%{version}.tar.gz
# https://bugzilla.redhat.com/show_bug.cgi?id=1707981
Patch0: 0001-Fix-crash-when-dumping-updateinfo-and-module-is-ommited-RhBug1707981.patch
BuildRequires: cmake BuildRequires: cmake
BuildRequires: gcc BuildRequires: gcc
@ -256,6 +258,9 @@ ln -sr %{buildroot}%{_bindir}/modifyrepo_c %{buildroot}%{_bindir}/modifyrepo
%endif %endif
%changelog %changelog
* Mon May 20 2019 Pavla Kratochvilova <pkratoch@redhat.com> - 0.13.2-2
- Backport patch to fix crash when dumping updateinfo and module is ommited (RhBug:1707981)
* Tue May 07 2019 Pavla Kratochvilova <pkratoch@redhat.com> - 0.13.2-1 * Tue May 07 2019 Pavla Kratochvilova <pkratoch@redhat.com> - 0.13.2-1
- Update to 0.13.2 - Update to 0.13.2
- Add support for reading and merging module metadata - Add support for reading and merging module metadata