Skip to content

Commit 89692c6

Browse files
authored
Merge pull request #2286 from Mab879/fix_2285
Fix segfault in error handling for cpe_item_parse
2 parents dd31572 + 5d2372c commit 89692c6

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

src/CPE/cpedict_priv.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,14 @@ struct cpe_item *cpe_item_parse(struct cpe_parser_ctx *ctx)
736736
} else if (xmlStrcmp(xmlTextReaderConstLocalName(reader), TAG_ITEM_METADATA_STR) == 0) {
737737
data = (char *)xmlTextReaderGetAttribute(reader, ATTR_MODIFICATION_DATE_STR);
738738
if ((data == NULL) || ((ret->metadata = cpe_item_metadata_new()) == NULL)) {
739-
oscap_seterr(OSCAP_EFAMILY_OSCAP,
740-
"Failed to parse item-metadata element within cpe-item/@name='%s'",
741-
cpe_name_get_as_str(ret->name));
739+
if (ret->name != NULL) {
740+
oscap_seterr(OSCAP_EFAMILY_OSCAP,
741+
"Failed to parse item-metadata element within cpe-item/@name='%s'",
742+
cpe_name_get_as_str(ret->name));
743+
} else {
744+
oscap_seterr(OSCAP_EFAMILY_OSCAP,
745+
"Failed to parse item-metadata element within cpe-item");
746+
}
742747
cpe_item_free(ret);
743748
free(data);
744749
return NULL;

tests/CPE/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_oscap_test("all.sh")
2+
add_oscap_test("openscap_2285_regression.sh")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
. $builddir/tests/test_common.sh
6+
7+
# oscap is expcted to fail here.
8+
# Turn off pipefail, run the cmd, the return code and return to safety.
9+
set +e +o pipefail
10+
$OSCAP info "${top_srcdir}/tests/CPE/openscap_2285_regression.xml"
11+
rc=$?
12+
set -e -o pipefail
13+
14+
15+
if [ "$rc" -eq 139 ]; then
16+
echo "oscap seg-faulted (exit status 139)"
17+
exit 1
18+
fi
19+
20+
if [ "$rc" -eq 0 ]; then
21+
echo "oscap did not error as expected"
22+
exit 1
23+
fi
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version='1.0' encoding='cp1250'?>
2+
<cpe-list xmlns="http://cpe.mit�e.org/dictionary/2.0" xmxsi="httce" xmlns:meta="0.2" xsiion="httd">
3+
<generator>
4+
<product_name>NaVD)</product_name>
5+
<product_version>T)</product_version> <schema_version>2.1</schema_version>
6+
<timestamp>200</timestamp> </generator>
7+
<cpe-item nameerator="OR" n="cpe:/a:-com:3c15100d"> <title lang="en-US">�luk�</title>
8+
<meta:item-metadata s="2044" />
9+
</cpe-item>
10+
11+
</cpe-list>

0 commit comments

Comments
 (0)