Blame SOURCES/openscap-1.3.5-yamlfilecontent-fix-field-names-PR_1619.patch

a1b1ec
diff --git a/src/OVAL/probes/independent/yamlfilecontent_probe.c b/src/OVAL/probes/independent/yamlfilecontent_probe.c
a1b1ec
index 6f18abf83..17741a240 100644
a1b1ec
--- a/src/OVAL/probes/independent/yamlfilecontent_probe.c
a1b1ec
+++ b/src/OVAL/probes/independent/yamlfilecontent_probe.c
a1b1ec
@@ -206,6 +206,7 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
a1b1ec
 	yaml_event_type_t event_type;
a1b1ec
 	bool sequence = false;
a1b1ec
 	bool mapping = false;
a1b1ec
+	bool fake_mapping = false;
a1b1ec
 	int index = 0;
a1b1ec
 	char *key = strdup("#");
a1b1ec
 
a1b1ec
@@ -224,21 +225,39 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
a1b1ec
 
a1b1ec
 		if (sequence) {
a1b1ec
 			if (event_type == YAML_SEQUENCE_END_EVENT) {
a1b1ec
-				sequence = false;
a1b1ec
+				if (fake_mapping) {
a1b1ec
+					fake_mapping = false;
a1b1ec
+					if (record && record->itemcount > 0) {
a1b1ec
+						oscap_list_add(values, record);
a1b1ec
+					} else {
a1b1ec
+						// Do not collect empty records
a1b1ec
+						oscap_htable_free0(record);
a1b1ec
+					}
a1b1ec
+					record = NULL;
a1b1ec
+				} else {
a1b1ec
+					sequence = false;
a1b1ec
+				}
a1b1ec
 			} else if (event_type == YAML_SEQUENCE_START_EVENT) {
a1b1ec
-				result_error("YAML path '%s' points to a multi-dimensional structure (sequence containing another sequence)", yaml_path_cstr);
a1b1ec
-				goto cleanup;
a1b1ec
+				if (mapping || fake_mapping) {
a1b1ec
+					result_error("YAML path '%s' points to a multi-dimensional structure (a map or a sequence containing other sequences)", yaml_path_cstr);
a1b1ec
+					goto cleanup;
a1b1ec
+				} else {
a1b1ec
+					fake_mapping = true;
a1b1ec
+					record = oscap_htable_new();
a1b1ec
+				}
a1b1ec
 			}
a1b1ec
 		} else {
a1b1ec
 			if (event_type == YAML_SEQUENCE_START_EVENT) {
a1b1ec
 				sequence = true;
a1b1ec
+				if (mapping)
a1b1ec
+					index++;
a1b1ec
 			}
a1b1ec
 		}
a1b1ec
 
a1b1ec
 		if (mapping) {
a1b1ec
 			if (event_type == YAML_MAPPING_END_EVENT) {
a1b1ec
 				mapping = false;
a1b1ec
-				if (record->itemcount > 0) {
a1b1ec
+				if (record && record->itemcount > 0) {
a1b1ec
 					oscap_list_add(values, record);
a1b1ec
 				} else {
a1b1ec
 					// Do not collect empty records
a1b1ec
@@ -255,6 +274,10 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
a1b1ec
 					result_error("YAML path '%s' points to an invalid structure (map containing another map)", yaml_path_cstr);
a1b1ec
 					goto cleanup;
a1b1ec
 				}
a1b1ec
+				if (fake_mapping) {
a1b1ec
+					result_error("YAML path '%s' points to a multi-dimensional structure (two-dimensional sequence containing a map)", yaml_path_cstr);
a1b1ec
+					goto cleanup;
a1b1ec
+				}
a1b1ec
 				mapping = true;
a1b1ec
 				sequence = false;
a1b1ec
 				index = 0;