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

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