From eaa95ecf03e6a95d98f2f6d301024cd27ff1e9f0 Mon Sep 17 00:00:00 2001 From: Chrissie Caulfield Date: Wed, 17 Aug 2022 13:17:33 +0100 Subject: [PATCH] lib: Fix some small bugs spotted by newest covscan (#471) * lib: Fix some small bugs spotted by newest covscan --- lib/ipc_socket.c | 1 + lib/ipcs.c | 7 ++++++- lib/log_blackbox.c | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/ipc_socket.c b/lib/ipc_socket.c index 178a634..a96d9c6 100644 --- a/lib/ipc_socket.c +++ b/lib/ipc_socket.c @@ -183,6 +183,7 @@ dgram_verify_msg_size(size_t max_msg_size) int32_t write_passed = 0; int32_t read_passed = 0; char buf[max_msg_size]; + memset (buf, 0, max_msg_size); if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) < 0) { qb_util_perror(LOG_DEBUG, "error calling socketpair()"); diff --git a/lib/ipcs.c b/lib/ipcs.c index 2404e13..1063609 100644 --- a/lib/ipcs.c +++ b/lib/ipcs.c @@ -705,7 +705,7 @@ _process_request_(struct qb_ipcs_connection *c, int32_t ms_timeout) } } - if (c && c->service->funcs.peek && c->service->funcs.reclaim) { + if (c->service->funcs.peek && c->service->funcs.reclaim) { c->service->funcs.reclaim(&c->request); } @@ -748,6 +748,11 @@ qb_ipcs_dispatch_connection_request(int32_t fd, int32_t revents, void *data) int32_t recvd = 0; ssize_t avail; + if (c == NULL) { + res = -EINVAL; + goto dispatch_cleanup; + } + if (revents & POLLNVAL) { qb_util_log(LOG_DEBUG, "NVAL conn (%s)", c->description); res = -EINVAL; diff --git a/lib/log_blackbox.c b/lib/log_blackbox.c index baef379..1e92ae5 100644 --- a/lib/log_blackbox.c +++ b/lib/log_blackbox.c @@ -264,6 +264,9 @@ qb_log_blackbox_print_from_file(const char *bb_filename) return -EIO; } chunk = malloc(max_size); + if (!chunk) { + goto cleanup; + } do { char *ptr; @@ -342,7 +345,7 @@ qb_log_blackbox_print_from_file(const char *bb_filename) int slen = strftime(time_buf, sizeof(time_buf), "%b %d %T", tm); - snprintf(time_buf+slen, sizeof(time_buf - slen), ".%03llu", timestamp.tv_nsec/QB_TIME_NS_IN_MSEC); + snprintf(time_buf+slen, sizeof(time_buf) - slen, ".%03llu", timestamp.tv_nsec/QB_TIME_NS_IN_MSEC); } else { snprintf(time_buf, sizeof(time_buf), "%ld", (long int)time_sec);