Fix patch

This commit is contained in:
Mattia Verga 2023-10-04 14:08:51 +02:00
parent a99b4d5a07
commit 015032f71a
2 changed files with 12 additions and 36 deletions

View File

@ -1,29 +1,7 @@
From 51fc7782472cdfb1905aa48f405c0f192ba6c373 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Wed, 27 Sep 2023 08:27:58 +0200
Subject: [PATCH] xml parsing: fix a crash on valid xml with but no comps
On input like:
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE variants PUBLIC "-//Red Hat, Inc.//DTD Variants info//EN" "variants.dtd">
<variants>
</variants>
```
the document is parsed but there is no `comps_doc` so we cannot work
with it.
Also adds a unit test.
---
libcomps/src/comps_parse.c | 6 +++---
libcomps/src/python/tests/__test.py | 9 +++++++++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/libcomps/src/comps_parse.c b/libcomps/src/comps_parse.c
index 18133a2..7b4bf3c 100644
--- a/libcomps/src/comps_parse.c
+++ b/libcomps/src/comps_parse.c
@@ -176,21 +176,21 @@ int comps_parse_validate_dtd(char *filename, char *dtd_file) {
diff -U 3 -dHrN a/libcomps/src/comps_parse.c b/libcomps/src/comps_parse.c
--- a/libcomps/src/comps_parse.c 2022-09-09 13:55:00.000000000 +0200
+++ b/libcomps/src/comps_parse.c 2023-10-04 14:00:50.722561035 +0200
@@ -176,21 +176,21 @@
}
void __comps_after_parse(COMPS_Parsed *parsed) {
@ -48,13 +26,12 @@ index 18133a2..7b4bf3c 100644
COMPS_OBJECT_DESTROY(parsed->comps_doc->doctype_pubid);
parsed->comps_doc->doctype_pubid = (COMPS_Str*)
COMPS_OBJECT_INCREF(parsed->doctype_pubid);
diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py
index ba4b349..18200c5 100644
--- a/libcomps/src/python/tests/__test.py
+++ b/libcomps/src/python/tests/__test.py
@@ -743,6 +743,15 @@ def test_xml(self):
# return code 1 is non fatal error
self.assertTrue(ret == 1, comps5.get_last_errors())
diff -U 3 -dHrN a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py
--- a/libcomps/src/python/tests/__test.py 2023-10-04 14:00:25.970189009 +0200
+++ b/libcomps/src/python/tests/__test.py 2023-10-04 14:00:50.723080381 +0200
@@ -1270,5 +1270,14 @@
#suite = unittest.TestLoader().loadTestsFromTestCase(EnvListTest)
#MyRunner(verbosity=2).run(suite)
+ VALID_XML_HEADER_NO_COMPS = """<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE variants PUBLIC "-//Red Hat, Inc.//DTD Variants info//EN" "variants.dtd">
@ -65,6 +42,3 @@ index ba4b349..18200c5 100644
+ # return code 1 is non fatal error
+ self.assertTrue(ret == 1, comps6.get_last_errors())
+
#@unittest.skip("")
def test_fedora(self):

View File

@ -10,7 +10,9 @@ URL: https://github.com/rpm-software-management/libcomps
Source0: %{url}/archive/%{version}/%{name}-%{version}.tar.gz
# Backported
# https://github.com/rpm-software-management/libcomps/pull/104
Patch: fix-fromxml_str-segfault.patch
# https://github.com/rpm-software-management/libcomps/pull/106
Patch: fix-a-crash-on-valid-xml-with-but-no-comps.patch
BuildRequires: gcc-c++