adamwill / rpms / openscap

Forked from rpms/openscap 3 years ago
Clone

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

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