From 33b6fe12f96888eed99dec7fec246f1d6caf3312 Mon Sep 17 00:00:00 2001 From: Todd Gill Date: Wed, 10 Feb 2021 11:07:45 -0500 Subject: [PATCH 1/3] coverity: for failure case fix return code from _set_channel_specs() remove return of -1 and return r (can be either EINVAL or ENOMEM) Signed-off-by: Todd Gill --- src/resource/worker-control.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resource/worker-control.c b/src/resource/worker-control.c index 27fb1da9..125ae010 100644 --- a/src/resource/worker-control.c +++ b/src/resource/worker-control.c @@ -1153,7 +1153,7 @@ static int _set_channel_specs(struct worker_control *worker_control, const struc return 0; fail: worker_control->channel_specs = mem_freen(worker_control->channel_specs); - return -1; + return r; } static int _init_worker_control(sid_resource_t *worker_control_res, const void *kickstart_data, void **data) From 9882100bd35b716e8eae2e9de7376dab8c97a961 Mon Sep 17 00:00:00 2001 From: Todd Gill Date: Wed, 10 Feb 2021 11:47:40 -0500 Subject: [PATCH 2/3] coverity: _export_kv_store() - log errno when write or lseek fail Signed-off-by: Todd Gill --- src/resource/ubridge.c | 47 ++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/resource/ubridge.c b/src/resource/ubridge.c index a68d3f5c..f8e12faf 100644 --- a/src/resource/ubridge.c +++ b/src/resource/ubridge.c @@ -3175,7 +3175,10 @@ static int _export_kv_store(sid_resource_t *cmd_res) export_fd = memfd_create("kv_store_export", MFD_CLOEXEC); /* Reserve space to write the overall data size. */ - lseek(export_fd, sizeof(bytes_written), SEEK_SET); + if (lseek(export_fd, sizeof(bytes_written), SEEK_SET) < 0) { + log_error_errno(ID(cmd_res), errno, "lseek failed"); + goto out; + }; // FIXME: maybe buffer first so there's only single write while ((value = kv_store_iter_next(iter, &size, &flags))) { @@ -3247,24 +3250,32 @@ static int _export_kv_store(sid_resource_t *cmd_res) /* FIXME: Try to reduce the "write" calls. */ if ((r_wr = write(export_fd, &flags, sizeof(flags))) == sizeof(flags)) bytes_written += r_wr; - else + else { + log_error_errno(ID(cmd_res), errno, "write failed"); goto out; + } if ((r_wr = write(export_fd, &key_size, sizeof(key_size))) == sizeof(key_size)) bytes_written += r_wr; - else + else { + log_error_errno(ID(cmd_res), errno, "write failed"); goto out; + } if ((r_wr = write(export_fd, &size, sizeof(size))) == sizeof(size)) bytes_written += r_wr; - else + else { + log_error_errno(ID(cmd_res), errno, "write failed"); goto out; + } if ((r_wr = write(export_fd, key, strlen(key) + 1)) == strlen(key) + 1) bytes_written += r_wr; - else + else { + log_error_errno(ID(cmd_res), errno, "write failed"); goto out; + } if (vector) { for (i = 0, size = 0; i < iov_size; i++) { @@ -3272,28 +3283,42 @@ static int _export_kv_store(sid_resource_t *cmd_res) if ((r_wr = write(export_fd, &iov[i].iov_len, sizeof(iov->iov_len))) == sizeof(iov->iov_len)) bytes_written += r_wr; - else + else { + log_error_errno(ID(cmd_res), errno, "write failed"); goto out; + } if ((r_wr = write(export_fd, iov[i].iov_base, iov[i].iov_len)) == iov[i].iov_len) bytes_written += r_wr; - else + else { + log_error_errno(ID(cmd_res), errno, "write failed"); goto out; + } } } else { if ((r_wr = write(export_fd, kv_value, size)) == size) bytes_written += r_wr; - else + else { + log_error_errno(ID(cmd_res), errno, "write failed"); goto out; + } } } - lseek(export_fd, 0, SEEK_SET); - if (write(export_fd, &bytes_written, sizeof(bytes_written)) < 0) + if (lseek(export_fd, 0, SEEK_SET) < 0) { + log_error_errno(ID(cmd_res), errno, "lseek failed"); goto out; - lseek(export_fd, 0, SEEK_SET); + } + if (write(export_fd, &bytes_written, sizeof(bytes_written)) < 0) { + log_error_errno(ID(cmd_res), errno, "write failed"); + goto out; + } + if (lseek(export_fd, 0, SEEK_SET) < 0) { + log_error_errno(ID(cmd_res), errno, "lseek failed"); + goto out; + } data_spec.data = NULL; data_spec.data_size = 0; From c041b116d5cc7727bb6e73aed3d4e5bf3cfef4a9 Mon Sep 17 00:00:00 2001 From: Todd Gill Date: Wed, 10 Feb 2021 12:03:33 -0500 Subject: [PATCH 3/3] coverity: check return value from dup2 and log error on failure Signed-off-by: Todd Gill --- src/resource/worker-control.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/resource/worker-control.c b/src/resource/worker-control.c index 125ae010..b1b77829 100644 --- a/src/resource/worker-control.c +++ b/src/resource/worker-control.c @@ -539,7 +539,10 @@ static int _setup_channel(sid_resource_t *owner, const char *alt_id, bool is_wor } if (chan->spec->wire.ext.used && chan->spec->wire.ext.pipe.fd_redir >= 0) { - dup2(chan->fd, chan->spec->wire.ext.pipe.fd_redir); + if (dup2(chan->fd, chan->spec->wire.ext.pipe.fd_redir) < 0) { + log_error_errno(id, errno, "Failed to redirect FD %d through channel %s : WORKER_WIRE_SOCKET", + chan->spec->wire.ext.pipe.fd_redir, chan->spec->id); + } close(chan->fd); } break;