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