From 69d50db53aab595b17526013a06ad5d9f575346c Mon Sep 17 00:00:00 2001 From: Jakub Rzeszutko Date: Fri, 13 Oct 2023 09:50:17 +0200 Subject: [PATCH] shell: fix a memory corruption coverity issue Added a condition to check if the size of the copied memory is a positive number. Fixes #58700 Fixes #58703 Signed-off-by: Jakub Rzeszutko --- subsys/shell/shell_log_backend.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/subsys/shell/shell_log_backend.c b/subsys/shell/shell_log_backend.c index 2a90478ee97..38ee97c3ff9 100644 --- a/subsys/shell/shell_log_backend.c +++ b/subsys/shell/shell_log_backend.c @@ -143,6 +143,9 @@ static bool copy_to_pbuffer(struct mpsc_pbuf_buffer *mpsc_buffer, uint8_t *src_data = (uint8_t *)msg + sizeof(struct mpsc_pbuf_hdr); size_t hdr_wlen = DIV_ROUND_UP(sizeof(struct mpsc_pbuf_hdr), sizeof(uint32_t)); + if (wlen <= hdr_wlen) { + return false; + } dst->hdr.data = msg->buf.hdr.data; memcpy(dst_data, src_data, (wlen - hdr_wlen) * sizeof(uint32_t));