From 2809cad50ed6571abd800ad426e206f4c50ab76d Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 1 Jul 2020 07:48:45 +0200 Subject: [PATCH] logging: Add fields initialization in z_log_msg_std_alloc Added initialization of ids fields in the log message in z_log_msg_std_alloc(). If user space is enabled then msg_free() function is reading log level and previously it may have been uninitialized. Signed-off-by: Krzysztof Chruscinski --- include/logging/log_msg.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/logging/log_msg.h b/include/logging/log_msg.h index 84c55c3e83b..39638f16f3d 100644 --- a/include/logging/log_msg.h +++ b/include/logging/log_msg.h @@ -7,6 +7,7 @@ #define ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_ #include +#include #include #ifdef __cplusplus @@ -326,6 +327,13 @@ static inline struct log_msg *z_log_msg_std_alloc(void) msg->hdr.ref_cnt = 1; msg->hdr.params.raw = 0U; msg->hdr.params.std.type = LOG_MSG_TYPE_STD; + + if (IS_ENABLED(CONFIG_USERSPACE)) { + /* it may be used in msg_free() function. */ + msg->hdr.ids.level = 0; + msg->hdr.ids.domain_id = 0; + msg->hdr.ids.source_id = 0; + } } return msg;