|
|
9f2d807 |
From c54f2b8768aa6c54c1810b040eb1ddcd7cfb089f Mon Sep 17 00:00:00 2001
|
|
|
9f2d807 |
From: Evgeny Kolesnikov <ekolesni@redhat.com>
|
|
|
9f2d807 |
Date: Wed, 4 Mar 2020 07:07:59 +0100
|
|
|
9f2d807 |
Subject: [PATCH] OVAL/probes: Add proper event cleanup for yamlfilecontent
|
|
|
9f2d807 |
probe
|
|
|
9f2d807 |
|
|
|
9f2d807 |
The event created by the yaml_parser_parse should be cleaned
|
|
|
9f2d807 |
with yaml_event_delete unless the event is used by the emitter.
|
|
|
9f2d807 |
---
|
|
|
9f2d807 |
.../independent/yamlfilecontent_probe.c | 21 +++++++++++--------
|
|
|
9f2d807 |
1 file changed, 12 insertions(+), 9 deletions(-)
|
|
|
9f2d807 |
|
|
|
9f2d807 |
diff --git a/src/OVAL/probes/independent/yamlfilecontent_probe.c b/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
9f2d807 |
index ae2f6828d..8fc4b32b2 100644
|
|
|
9f2d807 |
--- a/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
9f2d807 |
+++ b/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
9f2d807 |
@@ -168,6 +168,7 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
|
|
|
9f2d807 |
yaml_parser_set_input_file(&parser, yaml_file);
|
|
|
9f2d807 |
|
|
|
9f2d807 |
yaml_event_t event;
|
|
|
9f2d807 |
+ yaml_event_type_t event_type;
|
|
|
9f2d807 |
bool sequence = false;
|
|
|
9f2d807 |
|
|
|
9f2d807 |
do {
|
|
|
9f2d807 |
@@ -181,16 +182,16 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
|
|
|
9f2d807 |
ret = -1;
|
|
|
9f2d807 |
goto cleanup;
|
|
|
9f2d807 |
}
|
|
|
9f2d807 |
+
|
|
|
9f2d807 |
+ event_type = event.type;
|
|
|
9f2d807 |
if (!yaml_path_filter_event(yaml_path, &parser, &event,
|
|
|
9f2d807 |
YAML_PATH_FILTER_RETURN_ALL)) {
|
|
|
9f2d807 |
- yaml_event_delete(&event);
|
|
|
9f2d807 |
- continue;
|
|
|
9f2d807 |
+ goto next;
|
|
|
9f2d807 |
}
|
|
|
9f2d807 |
-
|
|
|
9f2d807 |
if (sequence) {
|
|
|
9f2d807 |
- if (event.type == YAML_SEQUENCE_END_EVENT) {
|
|
|
9f2d807 |
+ if (event_type == YAML_SEQUENCE_END_EVENT) {
|
|
|
9f2d807 |
sequence = false;
|
|
|
9f2d807 |
- } else if (event.type != YAML_SCALAR_EVENT) {
|
|
|
9f2d807 |
+ } else if (event_type != YAML_SCALAR_EVENT) {
|
|
|
9f2d807 |
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
|
|
|
9f2d807 |
"YAML path '%s' contains non-scalar in a sequence.",
|
|
|
9f2d807 |
yaml_path_cstr);
|
|
|
9f2d807 |
@@ -201,10 +202,10 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
|
|
|
9f2d807 |
goto cleanup;
|
|
|
9f2d807 |
}
|
|
|
9f2d807 |
} else {
|
|
|
9f2d807 |
- if (event.type == YAML_SEQUENCE_START_EVENT) {
|
|
|
9f2d807 |
+ if (event_type == YAML_SEQUENCE_START_EVENT) {
|
|
|
9f2d807 |
sequence = true;
|
|
|
9f2d807 |
}
|
|
|
9f2d807 |
- if (event.type == YAML_MAPPING_START_EVENT) {
|
|
|
9f2d807 |
+ if (event_type == YAML_MAPPING_START_EVENT) {
|
|
|
9f2d807 |
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
|
|
|
9f2d807 |
"YAML path '%s' matches a mapping.",
|
|
|
9f2d807 |
yaml_path_cstr);
|
|
|
9f2d807 |
@@ -229,7 +230,9 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
|
|
|
9f2d807 |
}
|
|
|
9f2d807 |
oscap_list_add(values, sexp);
|
|
|
9f2d807 |
}
|
|
|
9f2d807 |
- } while (event.type != YAML_STREAM_END_EVENT);
|
|
|
9f2d807 |
+next:
|
|
|
9f2d807 |
+ yaml_event_delete(&event);
|
|
|
9f2d807 |
+ } while (event_type != YAML_STREAM_END_EVENT);
|
|
|
9f2d807 |
|
|
|
9f2d807 |
cleanup:
|
|
|
9f2d807 |
yaml_parser_delete(&parser);
|