From caa2f9b30a0d5300a9a75a3340926834b30e436e Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 15 2020 18:49:53 +0000 Subject: Apply patch openscap-1.3.5-bump-yamlfilter-fix-field-names-PR_1619.patch patch_name: openscap-1.3.5-bump-yamlfilter-fix-field-names-PR_1619.patch present_in_specfile: true --- diff --git a/src/OVAL/probes/independent/yamlfilecontent_probe.c b/src/OVAL/probes/independent/yamlfilecontent_probe.c index 205510d..59f42f9 100644 --- a/src/OVAL/probes/independent/yamlfilecontent_probe.c +++ b/src/OVAL/probes/independent/yamlfilecontent_probe.c @@ -205,6 +205,7 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str yaml_event_type_t event_type; bool sequence = false; bool mapping = false; + bool fake_mapping = false; int index = 0; char *key = strdup("#"); @@ -224,21 +225,39 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str if (sequence) { if (event_type == YAML_SEQUENCE_END_EVENT) { - sequence = false; + if (fake_mapping) { + fake_mapping = false; + if (record && record->itemcount > 0) { + oscap_list_add(values, record); + } else { + // Do not collect empty records + oscap_htable_free0(record); + } + record = NULL; + } else { + sequence = false; + } } else if (event_type == YAML_SEQUENCE_START_EVENT) { - result_error("YAML path '%s' points to a multi-dimensional structure (sequence containing another sequence)", yaml_path_cstr); - goto cleanup; + if (mapping || fake_mapping) { + result_error("YAML path '%s' points to a multi-dimensional structure (a map or a sequence containing other sequences)", yaml_path_cstr); + goto cleanup; + } else { + fake_mapping = true; + record = oscap_htable_new(); + } } } else { if (event_type == YAML_SEQUENCE_START_EVENT) { sequence = true; + if (mapping) + index++; } } if (mapping) { if (event_type == YAML_MAPPING_END_EVENT) { mapping = false; - if (record->itemcount > 0) { + if (record && record->itemcount > 0) { oscap_list_add(values, record); } else { // Do not collect empty records @@ -255,6 +274,10 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str result_error("YAML path '%s' points to an invalid structure (map containing another map)", yaml_path_cstr); goto cleanup; } + if (fake_mapping) { + result_error("YAML path '%s' points to a multi-dimensional structure (two-dimensional sequence containing a map)", yaml_path_cstr); + goto cleanup; + } mapping = true; sequence = false; index = 0; diff --git a/tests/probes/yamlfilecontent/openshift-logging.yaml b/tests/probes/yamlfilecontent/openshift-logging.yaml index fb6a9d8..581a700 100644 --- a/tests/probes/yamlfilecontent/openshift-logging.yaml +++ b/tests/probes/yamlfilecontent/openshift-logging.yaml @@ -3,6 +3,18 @@ kind: "LogForwarding" metadata: name: instance namespace: openshift-logging +arrs: +- [1, 2, 3] +- [4, 5, 6] +items: +- allowHostDirVolumePlugin: false + defaultAddCapabilities: null + requiredDropCapabilities: ['KILL', 'ALL'] + name: ['Name', 'Oth'] +- allowHostDirVolumePlugin: false + defaultAddCapabilities: null + requiredDropCapabilities: ['OPS', 'KILL', 'ALL'] + name: ['2 Name', '2 Oth'] spec: disableDefaultForwarding: true outputs: diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.sh b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.sh index fd5e475..695a247 100755 --- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.sh +++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.sh @@ -19,7 +19,7 @@ function test_probes_yamlfilecontent_array { $OSCAP oval eval --results $RF $DF if [ -f $RF ]; then - verify_results "def" $DF $RF 2 && verify_results "tst" $DF $RF 3 + verify_results "def" $DF $RF 3 && verify_results "tst" $DF $RF 5 ret_val=$? else ret_val=1 diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.xml b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.xml index c05c5fb..77f57cd 100644 --- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.xml +++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_array.xml @@ -31,6 +31,17 @@ + + + + + + + + + + + @@ -49,6 +60,16 @@ + + + + + + + + + + @@ -71,6 +92,18 @@ .spec.outputs[0] + + /tmp + openshift-logging.yaml + .arrs[:][:] + + + + /tmp + openshift-logging.yaml + .arrs + + @@ -87,6 +120,12 @@ + + + + + + @@ -99,5 +138,11 @@ + + + 1|2|3|4|5|6 + + + diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.sh b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.sh index fc1e0ae..a942552 100755 --- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.sh +++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.sh @@ -19,7 +19,7 @@ function test_probes_yamlfilecontent_key { $OSCAP oval eval --results $RF $DF if [ -f $RF ]; then - verify_results "def" $DF $RF 6 && verify_results "tst" $DF $RF 7 + verify_results "def" $DF $RF 9 && verify_results "tst" $DF $RF 10 ret_val=$? else ret_val=1 diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.xml b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.xml index 05757d0..1697b54 100644 --- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.xml +++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_key.xml @@ -71,7 +71,7 @@ - + @@ -80,6 +80,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -116,9 +136,19 @@ - + + + + + + + + + + + @@ -170,6 +200,18 @@ openshift-logging.yaml .spec.outputs + + + /tmp + openshift-logging.yaml + .items[:]['requiredDropCapabilities','name','q','z'][:] + + + + /tmp + openshift-logging.yaml + .items[:].requiredDropCapabilities[:] + @@ -202,6 +244,19 @@ + + + ^KILL$ + Name + + + + + + ^KILL$ + + +