Skip to content

Commit a63f008

Browse files
committed
Ensure that YAML path matches only scalar or list of scalars
1 parent 723c46f commit a63f008

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/OVAL/probes/independent/yamlfilecontent_probe.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,42 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, uns
7373
yaml_event_t event;
7474
bool done = false;
7575

76+
bool sequence = false;
7677
do {
7778
if (yaml_parser_parse(&parser, &event)) {
7879
done = (event.type == YAML_STREAM_END_EVENT);
7980
if (yaml_path_filter_event(yaml_path, &parser, &event,
8081
YAML_PATH_FILTER_RETURN_ALL)) {
82+
83+
if (sequence) {
84+
if (event.type == YAML_SEQUENCE_END_EVENT) {
85+
sequence = false;
86+
} else if (event.type != YAML_SCALAR_EVENT) {
87+
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
88+
"YAML path '%s' contains non-scalar in a sequence.",
89+
yaml_path_cstr);
90+
probe_cobj_add_msg(probe_ctx_getresult(ctx), msg);
91+
SEXP_free(msg);
92+
probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR);
93+
ret = -1;
94+
goto cleanup;
95+
}
96+
} else {
97+
if (event.type == YAML_SEQUENCE_START_EVENT) {
98+
sequence = true;
99+
}
100+
if (event.type == YAML_MAPPING_START_EVENT) {
101+
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
102+
"YAML path '%s' matches a mapping.",
103+
yaml_path_cstr);
104+
probe_cobj_add_msg(probe_ctx_getresult(ctx), msg);
105+
SEXP_free(msg);
106+
probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR);
107+
ret = -1;
108+
goto cleanup;
109+
}
110+
}
111+
81112
if (!yaml_emitter_emit(&emitter, &event)) {
82113
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
83114
"YAML emitter error: yaml_emitter_emit returned 0: %s",

0 commit comments

Comments
 (0)