Skip to content

Commit fc476c2

Browse files
authored
Merge pull request #2027 from jan-cerny/issue2026
Fix partition probe for PCRE2
2 parents 73d957d + 3f35e89 commit fc476c2

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

src/OVAL/probes/unix/linux/partition_probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ int partition_probe_main(probe_ctx *ctx, void *probe_arg)
402402
rc = oscap_pcre_exec(re, mnt_entp->mnt_dir,
403403
strlen(mnt_entp->mnt_dir), 0, 0, NULL, 0);
404404

405-
if (rc == 0) {
405+
if (rc > OSCAP_PCRE_ERR_NOMATCH) {
406406
if (
407407
#if defined(HAVE_BLKID_GET_TAG_VALUE)
408408
collect_item(ctx, obj_over, mnt_entp, blkcache)

tests/probes/partition/test_probes_partition.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,30 @@ function test_probes_partition {
1010

1111
local ret_val=0;
1212
local DF="${srcdir}/test_probes_partition.xml"
13-
local RF="test_probes_partition.results.xml"
14-
echo "result file: $RF"
13+
local result="test_probes_partition.results.xml"
14+
echo "result file: $result"
1515
local stderr=$(mktemp $1.err.XXXXXX)
1616
echo "stderr file: $stderr"
1717

18-
[ -f $RF ] && rm -f $RF
18+
[ -f $result ] && rm -f $result
1919

20-
$OSCAP oval eval --results $RF $DF 2>$stderr
20+
$OSCAP oval eval --results $result $DF 2>$stderr
2121

22-
if [ -f $RF ]; then
23-
verify_results "def" $DF $RF 1 && verify_results "tst" $DF $RF 1
22+
if [ -f $result ]; then
23+
verify_results "def" $DF $result 3 && verify_results "tst" $DF $result 3
2424
ret_val=$?
2525
else
2626
ret_val=1
2727
fi
2828

29+
CO='/oval_results/results/system/oval_system_characteristics/collected_objects'
30+
assert_exists 1 $CO'/object[@id="oval:1:obj:1" and @flag="complete"]'
31+
assert_exists 1 $CO'/object[@id="oval:1:obj:2" and @flag="complete"]'
32+
assert_exists 1 $CO'/object[@id="oval:1:obj:3" and @flag="does not exist"]'
33+
SD='/oval_results/results/system/oval_system_characteristics/system_data'
34+
assert_exists 1 $SD'/lin-sys:partition_item'
35+
assert_exists 1 $SD'/lin-sys:partition_item/lin-sys:mount_point[text()="/proc"]'
36+
2937
grep -Ei "(W: |E: )" $stderr && ret_val=1 && echo "There is an error and/or a warning in the output!"
3038
rm $stderr
3139

tests/probes/partition/test_probes_partition.xml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@
2121
</criteria>
2222
</criteria>
2323
</definition>
24+
<definition class="compliance" version="1" id="oval:1:def:2"> <!-- comment="true" -->
25+
<metadata>
26+
<title></title>
27+
<description></description>
28+
</metadata>
29+
<criteria>
30+
<criteria operator="AND">
31+
<criterion test_ref="oval:1:tst:2"/>
32+
</criteria>
33+
</criteria>
34+
</definition>
35+
<definition class="compliance" version="1" id="oval:1:def:3"> <!-- comment="true" -->
36+
<metadata>
37+
<title></title>
38+
<description></description>
39+
</metadata>
40+
<criteria>
41+
<criteria operator="AND">
42+
<criterion test_ref="oval:1:tst:3"/>
43+
</criteria>
44+
</criteria>
45+
</definition>
2446

2547
</definitions>
2648

@@ -29,18 +51,34 @@
2951
<object object_ref="oval:1:obj:1"/>
3052
<state state_ref="oval:1:ste:1"/>
3153
</partition_test>
54+
<partition_test version="1" id="oval:1:tst:2" check="at least one" comment="true" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
55+
<object object_ref="oval:1:obj:2"/>
56+
<state state_ref="oval:1:ste:2"/>
57+
</partition_test>
58+
<partition_test version="1" id="oval:1:tst:3" check="at least one" check_existence="none_exist" comment="true" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
59+
<object object_ref="oval:1:obj:3"/>
60+
</partition_test>
3261
</tests>
3362

3463
<objects>
3564
<partition_object version="1" id="oval:1:obj:1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
3665
<mount_point>/proc</mount_point>
3766
</partition_object>
67+
<partition_object version="1" id="oval:1:obj:2" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
68+
<mount_point operation="pattern match">^\/proc$</mount_point>
69+
</partition_object>
70+
<partition_object version="1" id="oval:1:obj:3" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
71+
<mount_point operation="pattern match">^something.*without.*leading.*slash$</mount_point>
72+
</partition_object>
3873
</objects>
3974

4075
<states>
4176
<partition_state version="1" id="oval:1:ste:1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
4277
<device>proc</device>
4378
</partition_state>
79+
<partition_state version="1" id="oval:1:ste:2" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
80+
<device>proc</device>
81+
</partition_state>
4482
</states>
4583

46-
</oval_definitions>
84+
</oval_definitions>

0 commit comments

Comments
 (0)