Skip to content

Commit 0c33641

Browse files
jan-cernyevgenyz
authored andcommitted
Ensure xlink namespace exists
If the document doesn't contain the xlink namespace, we need to define it before we create the `xlink:href` attribute. This situation happens if the `data-stream-collection` root element of the input SCAP source data stream doesn't have the xlink namespace defined. Resolves: RHEL-34104
1 parent 7f94172 commit 0c33641

File tree

3 files changed

+109
-6
lines changed

3 files changed

+109
-6
lines changed

src/DS/rds.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,7 @@ static int _ds_rds_create_from_dom(xmlDocPtr *ret, xmlDocPtr sds_doc,
757757
free(tailoring_component_ref_id);
758758
xmlNsPtr xlink_ns = xmlSearchNsByHref(doc, sds_res_node, BAD_CAST xlink_ns_uri);
759759
if (!xlink_ns) {
760-
oscap_seterr(OSCAP_EFAMILY_XML,
761-
"Unable to find namespace '%s' in the XML DOM tree. "
762-
"This is most likely an internal error!.",
763-
xlink_ns_uri);
764-
free(tailoring_component_id);
765-
return -1;
760+
xlink_ns = xmlNewNs(tailoring_component_ref, BAD_CAST xlink_ns_uri, BAD_CAST "xlink");
766761
}
767762
char *tailoring_cref_href = oscap_sprintf("#%s", tailoring_component_id);
768763
free(tailoring_component_id);

tests/API/XCCDF/tailoring/all.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ function test_api_xccdf_tailoring_simple_include_in_arf {
9898
rm -f $result
9999
}
100100

101+
function test_api_xccdf_tailoring_simple_include_in_arf_xlink_namespace {
102+
# This test case is a regression test for RHEL-34104
103+
104+
local INPUT=$srcdir/$1
105+
local TAILORING=$srcdir/$2
106+
107+
result=`mktemp`
108+
stderr=`mktemp`
109+
$OSCAP xccdf eval --tailoring-file $TAILORING --results-arf $result $INPUT 2>"$stderr"
110+
if [ "$?" != "0" ]; then
111+
return 1
112+
fi
113+
114+
[ ! -s "$stderr" ]
115+
assert_exists 1 '/arf:asset-report-collection/arf:report-requests/arf:report-request/arf:content/ds:data-stream-collection/ds:component/Tailoring'
116+
117+
rm -f "$result"
118+
rm -f "$stderr"
119+
}
120+
101121
function test_api_xccdf_tailoring_profile_include_in_arf {
102122
local INPUT=$srcdir/$1
103123
local TAILORING=$srcdir/$2
@@ -167,6 +187,7 @@ test_run "test_api_xccdf_tailoring_oscap_info_11" test_api_xccdf_tailoring_oscap
167187
test_run "test_api_xccdf_tailoring_oscap_info_12" test_api_xccdf_tailoring_oscap_info simple-tailoring.xml 1
168188
test_run "test_api_xccdf_tailoring_autonegotiation" test_api_xccdf_tailoring_autonegotiation simple-tailoring-autonegotiation.xml xccdf_org.open-scap_profile_default 1
169189
test_run "test_api_xccdf_tailoring_simple_include_in_arf" test_api_xccdf_tailoring_simple_include_in_arf simple-xccdf.xml simple-tailoring.xml
190+
test_run "test_api_xccdf_tailoring_simple_include_in_arf_xlink_namespace" test_api_xccdf_tailoring_simple_include_in_arf_xlink_namespace xlink-test-simple-ds.xml simple-tailoring.xml
170191
test_run "test_api_xccdf_tailoring_profile_include_in_arf" test_api_xccdf_tailoring_profile_include_in_arf baseline.xccdf.xml baseline.tailoring.xml
171192
test_run "test_api_xccdf_tailoring_profile_generate_fix" test_api_xccdf_tailoring_profile_generate_fix baseline.xccdf.xml baseline.tailoring.xml
172193
test_run "test_api_xccdf_tailoring_profile_generate_guide" test_api_xccdf_tailoring_profile_generate_guide baseline.xccdf.xml baseline.tailoring.xml
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- This content is a part of regression test for RHEL-34104. In this test
3+
we don't define xlink namespace in the root element of this file but we
4+
define the xlink namespace in each component-ref element. -->
5+
<ds:data-stream-collection xmlns:ds="http://scap.nist.gov/schema/scap/source/1.2" xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog" id="scap_org.open-scap_collection_from_xccdf_simple-xccdf.xml" schematron-version="1.2">
6+
<ds:data-stream id="scap_org.open-scap_datastream_from_xccdf_simple-xccdf.xml" scap-version="1.2" use-case="OTHER">
7+
<ds:checklists>
8+
<ds:component-ref id="scap_org.open-scap_cref_simple-xccdf.xml" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#scap_org.open-scap_comp_simple-xccdf.xml">
9+
<cat:catalog>
10+
<cat:uri name="simple-oval.xml" uri="#scap_org.open-scap_cref_simple-oval.xml"/>
11+
</cat:catalog>
12+
</ds:component-ref>
13+
</ds:checklists>
14+
<ds:checks>
15+
<ds:component-ref id="scap_org.open-scap_cref_simple-oval.xml" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#scap_org.open-scap_comp_simple-oval.xml"/>
16+
</ds:checks>
17+
</ds:data-stream>
18+
<ds:component id="scap_org.open-scap_comp_simple-oval.xml" timestamp="2013-01-22T15:13:00">
19+
<oval_definitions xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">
20+
<generator>
21+
<oval:schema_version>5.10</oval:schema_version>
22+
<oval:timestamp>0001-01-01T00:00:00+00:00</oval:timestamp>
23+
</generator>
24+
<definitions>
25+
<definition class="compliance" version="1" id="oval:x:def:1">
26+
<metadata>
27+
<title>x</title>
28+
<description>x</description>
29+
<affected family="unix">
30+
<platform>x</platform>
31+
</affected>
32+
</metadata>
33+
<criteria comment="x" operator="OR">
34+
<criterion test_ref="oval:x:tst:1" comment="always pass"/>
35+
<criterion test_ref="oval:x:tst:2" comment="always fail"/>
36+
</criteria>
37+
</definition>
38+
<definition class="compliance" version="1" id="oval:x:def:2">
39+
<metadata>
40+
<title>x</title>
41+
<description>x</description>
42+
<affected family="unix">
43+
<platform>x</platform>
44+
</affected>
45+
</metadata>
46+
<criteria comment="x" operator="AND">
47+
<criterion test_ref="oval:x:tst:1" comment="always pass"/>
48+
<criterion test_ref="oval:x:tst:2" comment="always fail"/>
49+
</criteria>
50+
</definition>
51+
</definitions>
52+
<tests>
53+
<variable_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:1" check="all" comment="always pass" version="1">
54+
<object object_ref="oval:x:obj:1"/>
55+
</variable_test>
56+
<variable_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:2" check="all" check_existence="none_exist" comment="always fail" version="1">
57+
<object object_ref="oval:x:obj:1"/>
58+
</variable_test>
59+
</tests>
60+
<objects>
61+
<variable_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:obj:1" version="1" comment="x">
62+
<var_ref>oval:x:var:1</var_ref>
63+
</variable_object>
64+
</objects>
65+
<variables>
66+
<constant_variable id="oval:x:var:1" version="1" comment="x" datatype="string">
67+
<value>x</value>
68+
</constant_variable>
69+
</variables>
70+
</oval_definitions>
71+
</ds:component>
72+
<ds:component id="scap_org.open-scap_comp_simple-xccdf.xml" timestamp="2013-01-22T12:20:35">
73+
<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_moc.elpmaxe.www_benchmark_test">
74+
<status>incomplete</status>
75+
<version>1.0</version>
76+
<Profile id="xccdf_org.open-scap_profile_override">
77+
<title>Override</title>
78+
<select idref="xccdf_moc.elpmaxe.www_rule_1" selected="false"/>
79+
</Profile>
80+
<Rule selected="true" id="xccdf_moc.elpmaxe.www_rule_1">
81+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
82+
<check-content-ref href="simple-oval.xml" name="oval:x:def:1"/>
83+
</check>
84+
</Rule>
85+
</Benchmark>
86+
</ds:component>
87+
</ds:data-stream-collection>

0 commit comments

Comments
 (0)