Skip to content

Commit 3e5b01e

Browse files
authored
Merge pull request #2142 from jan-cerny/issue1962
Process CPE AL platforms if CPE dict isn't part of DS
2 parents 5c0235b + b97c728 commit 3e5b01e

5 files changed

Lines changed: 128 additions & 1 deletion

File tree

src/XCCDF/xccdf_session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ int xccdf_session_load_cpe(struct xccdf_session *session)
950950
}
951951

952952
if (xccdf_session_is_sds(session)) {
953+
_connect_cpe_session_with_sds(session);
953954
struct ds_sds_index *sds_idx = xccdf_session_get_sds_idx(session);
954955
if (sds_idx == NULL) {
955956
return -1;
@@ -968,7 +969,6 @@ int xccdf_session_load_cpe(struct xccdf_session *session)
968969
oscap_string_iterator_free(cpe_it);
969970
return 1;
970971
}
971-
_connect_cpe_session_with_sds(session);
972972
while (oscap_string_iterator_has_more(cpe_it)) {
973973
const char* cpe_filename = oscap_string_iterator_next(cpe_it);
974974

tests/DS/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ add_subdirectory("schematron")
1010
add_subdirectory("sds_detect_version")
1111
add_subdirectory("signed")
1212
add_subdirectory("validate")
13+
add_subdirectory("ds_without_cpe_dict")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_oscap_test("ds_without_cpe_dict.sh")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
. $builddir/tests/test_common.sh
4+
set -e -o pipefail
5+
6+
stdout=$(mktemp)
7+
stderr=$(mktemp)
8+
$OSCAP xccdf eval --progress $srcdir/ds_without_cpe_dict.xml > $stdout 2> $stderr
9+
[ -e $stderr ]
10+
grep -q "xccdf_moc.elpmaxe.www_rule_1:pass" $stdout
11+
! grep -q "xccdf_moc.elpmaxe.www_rule_1:notapplicable" $stdout
12+
! grep -q "Can't import OVAL definition model 'cpe-oval.xml' for CPE applicability checking" $stderr
13+
rm -rf $stdout $stderr
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ds:data-stream-collection xmlns:ds="http://scap.nist.gov/schema/scap/source/1.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog" id="scap_org.open-scap_collection_from_xccdf_xccdf.xml.xml" schematron-version="1.3">
3+
<ds:data-stream id="scap_org.open-scap_datastream_from_xccdf_xccdf.xml.xml" scap-version="1.3" use-case="OTHER">
4+
<ds:checklists>
5+
<ds:component-ref id="scap_org.open-scap_cref_xccdf.xml.xml" xlink:href="#scap_org.open-scap_comp_xccdf.xml.xml">
6+
<cat:catalog>
7+
<cat:uri name="oval.xml" uri="#scap_org.open-scap_cref_oval.xml"/>
8+
<cat:uri name="cpe-oval.xml" uri="#scap_org.open-scap_cref_cpe-oval.xml"/>
9+
</cat:catalog>
10+
</ds:component-ref>
11+
</ds:checklists>
12+
<ds:checks>
13+
<ds:component-ref id="scap_org.open-scap_cref_oval.xml" xlink:href="#scap_org.open-scap_comp_oval.xml"/>
14+
<ds:component-ref id="scap_org.open-scap_cref_cpe-oval.xml" xlink:href="#scap_org.open-scap_comp_cpe-oval.xml"/>
15+
</ds:checks>
16+
</ds:data-stream>
17+
<ds:component id="scap_org.open-scap_comp_oval.xml" timestamp="2023-03-22T10:30:34">
18+
<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">
19+
<generator>
20+
<oval:schema_version>5.11.1</oval:schema_version>
21+
<oval:timestamp>0001-01-01T00:00:00+00:00</oval:timestamp>
22+
</generator>
23+
<definitions>
24+
<definition class="compliance" version="1" id="oval:x:def:1">
25+
<metadata>
26+
<title>x</title>
27+
<description>x</description>
28+
<affected family="unix">
29+
<platform>x</platform>
30+
</affected>
31+
</metadata>
32+
<criteria comment="x" operator="OR">
33+
<criterion test_ref="oval:x:tst:1" comment="always pass"/>
34+
</criteria>
35+
</definition>
36+
</definitions>
37+
<tests>
38+
<variable_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:1" check="all" comment="always pass" version="1">
39+
<object object_ref="oval:x:obj:1"/>
40+
</variable_test>
41+
</tests>
42+
<objects>
43+
<variable_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:obj:1" version="1" comment="x">
44+
<var_ref>oval:x:var:1</var_ref>
45+
</variable_object>
46+
</objects>
47+
<variables>
48+
<constant_variable id="oval:x:var:1" version="1" comment="x" datatype="string">
49+
<value>x</value>
50+
</constant_variable>
51+
</variables>
52+
</oval_definitions>
53+
</ds:component>
54+
<ds:component id="scap_org.open-scap_comp_cpe-oval.xml" timestamp="2023-03-22T10:30:34">
55+
<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">
56+
<generator>
57+
<oval:schema_version>5.11.1</oval:schema_version>
58+
<oval:timestamp>0001-01-01T00:00:00+00:00</oval:timestamp>
59+
</generator>
60+
<definitions>
61+
<definition class="compliance" version="1" id="oval:my_custom_platform:def:2">
62+
<metadata>
63+
<title>x</title>
64+
<description>x</description>
65+
<affected family="unix">
66+
<platform>x</platform>
67+
</affected>
68+
</metadata>
69+
<criteria comment="x" operator="AND">
70+
<criterion test_ref="oval:x:tst:2" comment="always pass"/>
71+
</criteria>
72+
</definition>
73+
</definitions>
74+
<tests>
75+
<variable_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:tst:2" check="all" check_existence="any_exist" comment="always pass" version="1">
76+
<object object_ref="oval:x:obj:1"/>
77+
</variable_test>
78+
</tests>
79+
<objects>
80+
<variable_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" id="oval:x:obj:1" version="1" comment="x">
81+
<var_ref>oval:x:var:1</var_ref>
82+
</variable_object>
83+
</objects>
84+
<variables>
85+
<constant_variable id="oval:x:var:1" version="1" comment="x" datatype="string">
86+
<value>x</value>
87+
</constant_variable>
88+
</variables>
89+
</oval_definitions>
90+
</ds:component>
91+
<ds:component id="scap_org.open-scap_comp_xccdf.xml.xml" timestamp="2023-03-22T10:30:43">
92+
<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" xmlns:cpe2="http://cpe.mitre.org/language/2.0" id="xccdf_moc.elpmaxe.www_benchmark_test">
93+
<status>incomplete</status>
94+
<cpe2:platform-specification>
95+
<cpe2:platform id="platform1">
96+
<cpe2:title xml:lang="en-US">Test Platform 1</cpe2:title>
97+
<cpe2:logical-test operator="OR" negate="false">
98+
<cpe2:check-fact-ref system="http://oval.mitre.org/XMLSchema/oval-definitions-5" href="cpe-oval.xml" id-ref="oval:my_custom_platform:def:2"/>
99+
</cpe2:logical-test>
100+
</cpe2:platform>
101+
</cpe2:platform-specification>
102+
<version>1.0</version>
103+
<Rule selected="true" id="xccdf_moc.elpmaxe.www_rule_1">
104+
<title>Test Rule</title>
105+
<platform idref="#platform1"/>
106+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
107+
<check-content-ref href="oval.xml" name="oval:x:def:1"/>
108+
</check>
109+
</Rule>
110+
</Benchmark>
111+
</ds:component>
112+
</ds:data-stream-collection>

0 commit comments

Comments
 (0)