|
|
a1b1ec |
From 538c70780b49a36a4d2420ef93b87b78817dc14c Mon Sep 17 00:00:00 2001
|
|
|
a1b1ec |
From: Evgeny Kolesnikov <ekolesni@redhat.com>
|
|
|
a1b1ec |
Date: Mon, 26 Oct 2020 08:31:53 +0100
|
|
|
a1b1ec |
Subject: [PATCH] Covscan fixes
|
|
|
a1b1ec |
|
|
|
a1b1ec |
---
|
|
|
a1b1ec |
src/OVAL/probes/fsdev.c | 2 +-
|
|
|
a1b1ec |
src/OVAL/probes/independent/yamlfilecontent_probe.c | 5 +++--
|
|
|
a1b1ec |
src/OVAL/probes/unix/fileextendedattribute_probe.c | 2 +-
|
|
|
a1b1ec |
src/OVAL/probes/unix/linux/partition_probe.c | 2 +-
|
|
|
a1b1ec |
src/OVAL/probes/unix/xinetd_probe.c | 7 ++++++-
|
|
|
a1b1ec |
src/XCCDF/xccdf_session.c | 4 ++--
|
|
|
a1b1ec |
utils/oscap-tool.c | 6 +++++-
|
|
|
a1b1ec |
utils/oscap-xccdf.c | 3 +--
|
|
|
a1b1ec |
8 files changed, 20 insertions(+), 11 deletions(-)
|
|
|
a1b1ec |
|
|
|
a1b1ec |
diff --git a/src/OVAL/probes/fsdev.c b/src/OVAL/probes/fsdev.c
|
|
|
a1b1ec |
index b2b984441..c82ab620b 100644
|
|
|
a1b1ec |
--- a/src/OVAL/probes/fsdev.c
|
|
|
a1b1ec |
+++ b/src/OVAL/probes/fsdev.c
|
|
|
a1b1ec |
@@ -219,7 +219,7 @@ static fsdev_t *__fsdev_init(fsdev_t *lfs)
|
|
|
a1b1ec |
endmntent(fp);
|
|
|
a1b1ec |
|
|
|
a1b1ec |
void *new_ids = realloc(lfs->ids, sizeof(dev_t) * i);
|
|
|
a1b1ec |
- if (new_ids == NULL) {
|
|
|
a1b1ec |
+ if (new_ids == NULL && i > 0) {
|
|
|
a1b1ec |
e = errno;
|
|
|
a1b1ec |
free(lfs->ids);
|
|
|
a1b1ec |
free(lfs);
|
|
|
a1b1ec |
diff --git a/src/OVAL/probes/independent/yamlfilecontent_probe.c b/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
a1b1ec |
index 6f18abf83..e7e6cb3f5 100644
|
|
|
a1b1ec |
--- a/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
a1b1ec |
+++ b/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
a1b1ec |
@@ -216,12 +216,13 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
|
|
|
a1b1ec |
result_error("YAML parser error: %s", parser.problem);
|
|
|
a1b1ec |
goto cleanup;
|
|
|
a1b1ec |
}
|
|
|
a1b1ec |
+
|
|
|
a1b1ec |
+ event_type = event.type;
|
|
|
a1b1ec |
+
|
|
|
a1b1ec |
if (yaml_path_filter_event(yaml_path, &parser, &event) == YAML_PATH_FILTER_RESULT_OUT) {
|
|
|
a1b1ec |
goto next;
|
|
|
a1b1ec |
}
|
|
|
a1b1ec |
|
|
|
a1b1ec |
- event_type = event.type;
|
|
|
a1b1ec |
-
|
|
|
a1b1ec |
if (sequence) {
|
|
|
a1b1ec |
if (event_type == YAML_SEQUENCE_END_EVENT) {
|
|
|
a1b1ec |
sequence = false;
|
|
|
a1b1ec |
diff --git a/src/OVAL/probes/unix/fileextendedattribute_probe.c b/src/OVAL/probes/unix/fileextendedattribute_probe.c
|
|
|
a1b1ec |
index b442ea540..ee853886a 100644
|
|
|
a1b1ec |
--- a/src/OVAL/probes/unix/fileextendedattribute_probe.c
|
|
|
a1b1ec |
+++ b/src/OVAL/probes/unix/fileextendedattribute_probe.c
|
|
|
a1b1ec |
@@ -298,7 +298,7 @@ static int file_cb(const char *prefix, const char *p, const char *f, void *ptr,
|
|
|
a1b1ec |
|
|
|
a1b1ec |
// Allocate buffer, '+1' is for trailing '\0'
|
|
|
a1b1ec |
void *new_xattr_val = realloc(xattr_val, sizeof(char) * (xattr_vallen + 1));
|
|
|
a1b1ec |
- if (xattr_val == NULL) {
|
|
|
a1b1ec |
+ if (new_xattr_val == NULL) {
|
|
|
a1b1ec |
dE("Failed to allocate memory for xattr_val");
|
|
|
a1b1ec |
free(xattr_val);
|
|
|
a1b1ec |
goto exit;
|
|
|
a1b1ec |
diff --git a/src/OVAL/probes/unix/linux/partition_probe.c b/src/OVAL/probes/unix/linux/partition_probe.c
|
|
|
a1b1ec |
index a74c0323a..adb244b04 100644
|
|
|
a1b1ec |
--- a/src/OVAL/probes/unix/linux/partition_probe.c
|
|
|
a1b1ec |
+++ b/src/OVAL/probes/unix/linux/partition_probe.c
|
|
|
a1b1ec |
@@ -207,7 +207,7 @@ static int collect_item(probe_ctx *ctx, oval_schema_version_t over, struct mnten
|
|
|
a1b1ec |
mnt_ocnt = add_mnt_opt(&mnt_opts, mnt_ocnt, "move");
|
|
|
a1b1ec |
}
|
|
|
a1b1ec |
|
|
|
a1b1ec |
- dD("mnt_ocnt = %d, mnt_opts[mnt_ocnt]=%p", mnt_ocnt, mnt_opts[mnt_ocnt]);
|
|
|
a1b1ec |
+ dD("mnt_ocnt = %d, mnt_opts[mnt_ocnt]=%p", mnt_ocnt, mnt_opts == NULL ? NULL : mnt_opts[mnt_ocnt]);
|
|
|
a1b1ec |
|
|
|
a1b1ec |
/*
|
|
|
a1b1ec |
* "Correct" the type (this won't be (hopefully) needed in a later version
|
|
|
a1b1ec |
diff --git a/src/OVAL/probes/unix/xinetd_probe.c b/src/OVAL/probes/unix/xinetd_probe.c
|
|
|
a1b1ec |
index 75b12f95b..d61c7d547 100644
|
|
|
a1b1ec |
--- a/src/OVAL/probes/unix/xinetd_probe.c
|
|
|
a1b1ec |
+++ b/src/OVAL/probes/unix/xinetd_probe.c
|
|
|
a1b1ec |
@@ -566,7 +566,12 @@ static int xiconf_add_cfile(xiconf_t *xiconf, const char *path, int depth)
|
|
|
a1b1ec |
}
|
|
|
a1b1ec |
|
|
|
a1b1ec |
xifile->depth = depth;
|
|
|
a1b1ec |
- xiconf->cfile = realloc(xiconf->cfile, sizeof(xiconf_file_t *) * ++xiconf->count);
|
|
|
a1b1ec |
+ void *cfile = realloc(xiconf->cfile, sizeof(xiconf_file_t *) * ++xiconf->count);
|
|
|
a1b1ec |
+ if (cfile == NULL) {
|
|
|
a1b1ec |
+ dE("Failed re-allocate memory for cfile");
|
|
|
a1b1ec |
+ return (-1);
|
|
|
a1b1ec |
+ }
|
|
|
a1b1ec |
+ xiconf->cfile = cfile;
|
|
|
a1b1ec |
xiconf->cfile[xiconf->count - 1] = xifile;
|
|
|
a1b1ec |
|
|
|
a1b1ec |
dD("Added new file to the cfile queue: %s; fi=%zu", path, xiconf->count - 1);
|
|
|
a1b1ec |
diff --git a/src/XCCDF/xccdf_session.c b/src/XCCDF/xccdf_session.c
|
|
|
a1b1ec |
index 8bd394e2f..f1b837959 100644
|
|
|
a1b1ec |
--- a/src/XCCDF/xccdf_session.c
|
|
|
a1b1ec |
+++ b/src/XCCDF/xccdf_session.c
|
|
|
a1b1ec |
@@ -286,9 +286,9 @@ static struct oscap_source *xccdf_session_extract_arf_source(struct xccdf_sessio
|
|
|
a1b1ec |
}
|
|
|
a1b1ec |
struct tm *tm_mtime = malloc(sizeof(struct tm));
|
|
|
a1b1ec |
#ifdef OS_WINDOWS
|
|
|
a1b1ec |
- tm_mtime = localtime_s(tm_mtime, &file_stat.st_mtime);
|
|
|
a1b1ec |
+ localtime_s(tm_mtime, &file_stat.st_mtime);
|
|
|
a1b1ec |
#else
|
|
|
a1b1ec |
- tm_mtime = localtime_r(&file_stat.st_mtime, tm_mtime);
|
|
|
a1b1ec |
+ localtime_r(&file_stat.st_mtime, tm_mtime);
|
|
|
a1b1ec |
#endif
|
|
|
a1b1ec |
strftime(tailoring_doc_timestamp, max_timestamp_len,
|
|
|
a1b1ec |
"%Y-%m-%dT%H:%M:%S", tm_mtime);
|
|
|
a1b1ec |
diff --git a/utils/oscap-tool.c b/utils/oscap-tool.c
|
|
|
a1b1ec |
index 9bfe52697..660a19047 100644
|
|
|
a1b1ec |
--- a/utils/oscap-tool.c
|
|
|
a1b1ec |
+++ b/utils/oscap-tool.c
|
|
|
a1b1ec |
@@ -315,7 +315,10 @@ static void getopt_parse_env(struct oscap_module *module, int *argc, char ***arg
|
|
|
a1b1ec |
opt = oscap_strtok_r(opts, delim, &state);
|
|
|
a1b1ec |
while (opt != NULL) {
|
|
|
a1b1ec |
eargc++;
|
|
|
a1b1ec |
- eargv = realloc(eargv, eargc * sizeof(char *));
|
|
|
a1b1ec |
+ void *new_eargv = realloc(eargv, eargc * sizeof(char *));
|
|
|
a1b1ec |
+ if (new_eargv == NULL)
|
|
|
a1b1ec |
+ goto exit;
|
|
|
a1b1ec |
+ eargv = new_eargv;
|
|
|
a1b1ec |
eargv[eargc - 1] = strdup(opt);
|
|
|
a1b1ec |
opt = oscap_strtok_r(NULL, delim, &state);
|
|
|
a1b1ec |
}
|
|
|
a1b1ec |
@@ -334,6 +337,7 @@ static void getopt_parse_env(struct oscap_module *module, int *argc, char ***arg
|
|
|
a1b1ec |
|
|
|
a1b1ec |
*argc = nargc;
|
|
|
a1b1ec |
*argv = nargv;
|
|
|
a1b1ec |
+exit:
|
|
|
a1b1ec |
free(opts);
|
|
|
a1b1ec |
free(eargv);
|
|
|
a1b1ec |
}
|
|
|
a1b1ec |
diff --git a/utils/oscap-xccdf.c b/utils/oscap-xccdf.c
|
|
|
a1b1ec |
index af337b844..0a9ae5270 100644
|
|
|
a1b1ec |
--- a/utils/oscap-xccdf.c
|
|
|
a1b1ec |
+++ b/utils/oscap-xccdf.c
|
|
|
a1b1ec |
@@ -610,8 +610,7 @@ int app_evaluate_xccdf(const struct oscap_action *action)
|
|
|
a1b1ec |
|
|
|
a1b1ec |
/* syslog message */
|
|
|
a1b1ec |
#if defined(HAVE_SYSLOG_H)
|
|
|
a1b1ec |
- syslog(priority, "Evaluation finished. Return code: %d, Base score %f.", evaluation_result,
|
|
|
a1b1ec |
- session == NULL ? 0 : xccdf_session_get_base_score(session));
|
|
|
a1b1ec |
+ syslog(priority, "Evaluation finished. Return code: %d, Base score %f.", evaluation_result, xccdf_session_get_base_score(session));
|
|
|
a1b1ec |
#endif
|
|
|
a1b1ec |
|
|
|
a1b1ec |
xccdf_session_set_xccdf_export(session, action->f_results);
|