From 2be770a56fa34dde299798f73c9a7b081a3bc808 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 8 Jul 2024 11:50:01 -0400 Subject: [PATCH] Fix: sessiond: g++ reports shm_path truncation issue MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit On the CI, g++ reports: char* strncpy(char*, const char*, size_t)' specified bound 4096 equals destination size [-Wstringop-truncation] The shm_path provided by liblttng-ctl is truncated to PATH_MAX regardless of its contents. LTTN_ERR_INVALID is returned if the shm_path is not null terminated. Signed-off-by: Jérémie Galarneau Change-Id: Ie369f2ee368c70e2b3b41c45a69da7e6d9fa45f8 --- src/bin/lttng-sessiond/cmd.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index a0e9c49e6..2d081a964 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -5427,10 +5427,9 @@ int cmd_set_session_shm_path(const ltt_session::locked_ref& session, const char return LTTNG_ERR_SESSION_STARTED; } - strncpy(session->shm_path, shm_path, sizeof(session->shm_path)); - session->shm_path[sizeof(session->shm_path) - 1] = '\0'; - - return LTTNG_OK; + /* Report an error if shm_path is too long or not null-terminated. */ + const auto copy_ret = lttng_strncpy(session->shm_path, shm_path, sizeof(session->shm_path)); + return copy_ret == 0 ? LTTNG_OK : LTTNG_ERR_INVALID; } /* -- 2.34.1