Skip to content

Commit 0e79be0

Browse files
authored
Merge pull request #1494 from evgenyz/fix_yaml_event_cleanup
OVAL/probes: Add proper event cleanup for yamlfilecontent probe
2 parents 37fd155 + c54f2b8 commit 0e79be0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/OVAL/probes/independent/yamlfilecontent_probe.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
168168
yaml_parser_set_input_file(&parser, yaml_file);
169169

170170
yaml_event_t event;
171+
yaml_event_type_t event_type;
171172
bool sequence = false;
172173

173174
do {
@@ -181,16 +182,16 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
181182
ret = -1;
182183
goto cleanup;
183184
}
185+
186+
event_type = event.type;
184187
if (!yaml_path_filter_event(yaml_path, &parser, &event,
185188
YAML_PATH_FILTER_RETURN_ALL)) {
186-
yaml_event_delete(&event);
187-
continue;
189+
goto next;
188190
}
189-
190191
if (sequence) {
191-
if (event.type == YAML_SEQUENCE_END_EVENT) {
192+
if (event_type == YAML_SEQUENCE_END_EVENT) {
192193
sequence = false;
193-
} else if (event.type != YAML_SCALAR_EVENT) {
194+
} else if (event_type != YAML_SCALAR_EVENT) {
194195
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
195196
"YAML path '%s' contains non-scalar in a sequence.",
196197
yaml_path_cstr);
@@ -201,10 +202,10 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
201202
goto cleanup;
202203
}
203204
} else {
204-
if (event.type == YAML_SEQUENCE_START_EVENT) {
205+
if (event_type == YAML_SEQUENCE_START_EVENT) {
205206
sequence = true;
206207
}
207-
if (event.type == YAML_MAPPING_START_EVENT) {
208+
if (event_type == YAML_MAPPING_START_EVENT) {
208209
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
209210
"YAML path '%s' matches a mapping.",
210211
yaml_path_cstr);
@@ -215,7 +216,7 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
215216
goto cleanup;
216217
}
217218
}
218-
if (event.type == YAML_SCALAR_EVENT) {
219+
if (event_type == YAML_SCALAR_EVENT) {
219220
SEXP_t *sexp = yaml_scalar_event_to_sexp(&event);
220221
if (sexp == NULL) {
221222
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
@@ -229,7 +230,9 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
229230
}
230231
oscap_list_add(values, sexp);
231232
}
232-
} while (event.type != YAML_STREAM_END_EVENT);
233+
next:
234+
yaml_event_delete(&event);
235+
} while (event_type != YAML_STREAM_END_EVENT);
233236

234237
cleanup:
235238
yaml_parser_delete(&parser);

0 commit comments

Comments
 (0)