Skip to content

Commit 821e63a

Browse files
committed
Reduce code nesting
1 parent a63f008 commit 821e63a

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

src/OVAL/probes/independent/yamlfilecontent_probe.c

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -75,54 +75,7 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, uns
7575

7676
bool sequence = false;
7777
do {
78-
if (yaml_parser_parse(&parser, &event)) {
79-
done = (event.type == YAML_STREAM_END_EVENT);
80-
if (yaml_path_filter_event(yaml_path, &parser, &event,
81-
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-
112-
if (!yaml_emitter_emit(&emitter, &event)) {
113-
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
114-
"YAML emitter error: yaml_emitter_emit returned 0: %s",
115-
emitter.problem);
116-
probe_cobj_add_msg(probe_ctx_getresult(ctx), msg);
117-
SEXP_free(msg);
118-
probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR);
119-
ret = -1;
120-
goto cleanup;
121-
}
122-
} else {
123-
yaml_event_delete(&event);
124-
}
125-
} else {
78+
if (!yaml_parser_parse(&parser, &event)) {
12679
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
12780
"YAML parser error: yaml_parse_parse returned 0: %s",
12881
parser.problem);
@@ -132,6 +85,53 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, uns
13285
ret = -1;
13386
goto cleanup;
13487
}
88+
done = (event.type == YAML_STREAM_END_EVENT);
89+
if (!yaml_path_filter_event(yaml_path, &parser, &event,
90+
YAML_PATH_FILTER_RETURN_ALL)) {
91+
yaml_event_delete(&event);
92+
continue;
93+
}
94+
95+
if (sequence) {
96+
if (event.type == YAML_SEQUENCE_END_EVENT) {
97+
sequence = false;
98+
} else if (event.type != YAML_SCALAR_EVENT) {
99+
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
100+
"YAML path '%s' contains non-scalar in a sequence.",
101+
yaml_path_cstr);
102+
probe_cobj_add_msg(probe_ctx_getresult(ctx), msg);
103+
SEXP_free(msg);
104+
probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR);
105+
ret = -1;
106+
goto cleanup;
107+
}
108+
} else {
109+
if (event.type == YAML_SEQUENCE_START_EVENT) {
110+
sequence = true;
111+
}
112+
if (event.type == YAML_MAPPING_START_EVENT) {
113+
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
114+
"YAML path '%s' matches a mapping.",
115+
yaml_path_cstr);
116+
probe_cobj_add_msg(probe_ctx_getresult(ctx), msg);
117+
SEXP_free(msg);
118+
probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR);
119+
ret = -1;
120+
goto cleanup;
121+
}
122+
}
123+
124+
if (!yaml_emitter_emit(&emitter, &event)) {
125+
SEXP_t *msg = probe_msg_creatf(OVAL_MESSAGE_LEVEL_ERROR,
126+
"YAML emitter error: yaml_emitter_emit returned 0: %s",
127+
emitter.problem);
128+
probe_cobj_add_msg(probe_ctx_getresult(ctx), msg);
129+
SEXP_free(msg);
130+
probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_ERROR);
131+
ret = -1;
132+
goto cleanup;
133+
}
134+
135135
} while (!done);
136136

137137
/* string output_buffer contains '\n' at the end */

0 commit comments

Comments
 (0)