From 5c7d6083a96323786dffa1112e3b862cf229f2b3 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 6 May 2024 23:59:59 +0200 Subject: [PATCH] cov: annotate to silent some coverity warning --- daemons/dmeventd/dmeventd.c | 4 +++- lib/metadata/lv_manip.c | 2 ++ tools/lvmcmdline.c | 1 + tools/vgcfgbackup.c | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index 43e8e724f..58f1caa58 100644 --- a/daemons/dmeventd/dmeventd.c +++ b/daemons/dmeventd/dmeventd.c @@ -1441,7 +1441,8 @@ static int _open_fifo(const char *path) } else if (!S_ISFIFO(st.st_mode) || st.st_uid || (st.st_mode & (S_IEXEC | S_IRWXG | S_IRWXO))) { log_warn("WARNING: %s has wrong attributes: Replacing.", path); - if (unlink(path)) { + /* coverity[toctou] don't care, path is going to be recreated */ + if (unlink(path) && (errno != ENOENT)) { log_sys_error("unlink", path); return -1; } @@ -1449,6 +1450,7 @@ static int _open_fifo(const char *path) /* Create fifo. */ (void) dm_prepare_selinux_context(path, S_IFIFO); + /* coverity[toctou] revalidating things again */ if ((mkfifo(path, 0600) == -1) && errno != EEXIST) { log_sys_error("mkfifo", path); (void) dm_prepare_selinux_context(NULL, 0); diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 8bf3b1802..a616cfe79 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -7167,6 +7167,8 @@ char *generate_lv_name(struct volume_group *vg, const char *format, high = i; } + /* only internally passed %d are supported */ + /* coverity[non_const_printf_format_string] */ if (dm_snprintf(buffer, len, format, high + 1) < 0) return NULL; diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 38e3ce190..ceced2379 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -3555,6 +3555,7 @@ static void _nonroot_warning(void) log_warn("WARNING: Running as a non-root user. Functionality may be unavailable."); } +/* coverity[-tainted_data_sink:arg-1] */ int lvm2_main(int argc, char **argv) { const char *base; diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c index 49779cabe..e9ef402cc 100644 --- a/tools/vgcfgbackup.c +++ b/tools/vgcfgbackup.c @@ -33,6 +33,7 @@ static char *_expand_filename(const char *template, const char *vg_name, return NULL; } + /* coverity[non_const_printf_format_string] */ if (dm_snprintf(filename, PATH_MAX, template, vg_name) < 0) { log_error("Error processing filename template %s", template);