Skip to content

Commit

Permalink
xml parsing: fix a crash on valid xml with but no comps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kontura authored and jan-kolarik committed Oct 4, 2023
1 parent 62c69d8 commit 51fc778
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libcomps/src/comps_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions libcomps/src/python/tests/__test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 51fc778

Please sign in to comment.