Backport additional patch to fix segfault in fromxml_str
This commit is contained in:
parent
29fe8782e6
commit
a99b4d5a07
70
fix-a-crash-on-valid-xml-with-but-no-comps.patch
Normal file
70
fix-a-crash-on-valid-xml-with-but-no-comps.patch
Normal file
@ -0,0 +1,70 @@
|
||||
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) {
|
||||
}
|
||||
|
||||
void __comps_after_parse(COMPS_Parsed *parsed) {
|
||||
- if (parsed->doctype_name) {
|
||||
+ if (parsed->doctype_name && parsed->comps_doc) {
|
||||
COMPS_OBJECT_DESTROY(parsed->comps_doc->doctype_name);
|
||||
parsed->comps_doc->doctype_name = (COMPS_Str*)
|
||||
COMPS_OBJECT_INCREF(parsed->doctype_name);
|
||||
} else {
|
||||
//parsed->comps_doc->doctype_name = comps_str(comps_default_doctype_name);
|
||||
}
|
||||
- if (parsed->doctype_sysid) {
|
||||
+ if (parsed->doctype_sysid && parsed->comps_doc) {
|
||||
COMPS_OBJECT_DESTROY(parsed->comps_doc->doctype_sysid);
|
||||
parsed->comps_doc->doctype_sysid = (COMPS_Str*)
|
||||
COMPS_OBJECT_INCREF(parsed->doctype_sysid);
|
||||
} else {
|
||||
//parsed->comps_doc->doctype_sysid = comps_str(comps_default_doctype_sysid);
|
||||
}
|
||||
- if (parsed->doctype_pubid) {
|
||||
+ if (parsed->doctype_pubid && parsed->comps_doc) {
|
||||
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())
|
||||
|
||||
+ VALID_XML_HEADER_NO_COMPS = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
+ <!DOCTYPE variants PUBLIC "-//Red Hat, Inc.//DTD Variants info//EN" "variants.dtd">
|
||||
+ <variants>
|
||||
+ </variants>"""
|
||||
+ comps6 = libcomps.Comps()
|
||||
+ ret = comps6.fromxml_str(str(VALID_XML_HEADER_NO_COMPS))
|
||||
+ # return code 1 is non fatal error
|
||||
+ self.assertTrue(ret == 1, comps6.get_last_errors())
|
||||
+
|
||||
|
||||
#@unittest.skip("")
|
||||
def test_fedora(self):
|
@ -2,7 +2,7 @@
|
||||
|
||||
Name: libcomps
|
||||
Version: 0.1.19
|
||||
Release: 4%{?dist}
|
||||
Release: 5%{?dist}
|
||||
Summary: Comps XML file manipulation library
|
||||
|
||||
License: GPL-2.0-or-later
|
||||
@ -11,6 +11,7 @@ Source0: %{url}/archive/%{version}/%{name}-%{version}.tar.gz
|
||||
|
||||
# Backported
|
||||
Patch: fix-fromxml_str-segfault.patch
|
||||
Patch: fix-a-crash-on-valid-xml-with-but-no-comps.patch
|
||||
|
||||
BuildRequires: gcc-c++
|
||||
BuildRequires: cmake
|
||||
@ -119,6 +120,9 @@ popd
|
||||
%{python3_sitearch}/%{name}-%{version}-py%{python3_version}.egg-info
|
||||
|
||||
%changelog
|
||||
* Wed Oct 04 2023 Mattia Verga <mattia.verga@proton.me> - 0.1.19-5
|
||||
- Backport additional patch to fix segfault in fromxml_str
|
||||
|
||||
* Tue Sep 05 2023 Mattia Verga <mattia.verga@proton.me> - 0.1.19-4
|
||||
- Backport patch to fix segfault in fromxml_str
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user