From 8e5a760ae61c940eae3f0caf0358e7bf76eddbeb Mon Sep 17 00:00:00 2001 From: Arnaud Pouliquen Date: Mon, 30 Sep 2024 10:50:08 +0200 Subject: [PATCH] lib: rpmsg: replace strncpy with internal strlcpy The strncpy function does not ensure that the destination string is null-terminated. To address this issue, replace strncpy with the internal strlcpy function, which guarantees null-termination of the destination string. Note: (void)strlcpy(...) indicates that the return value is intentionally ignored. Signed-off-by: Arnaud Pouliquen (cherry picked from commit e83acc98ad18f27bd1c12de808aaed84a0091791) Upstream PR: https://github.com/OpenAMP/open-amp/pull/620 Signed-off-by: Tomi Fontanilles --- open-amp/lib/rpmsg/rpmsg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/open-amp/lib/rpmsg/rpmsg.c b/open-amp/lib/rpmsg/rpmsg.c index 39774bc..b79b9bb 100644 --- a/open-amp/lib/rpmsg/rpmsg.c +++ b/open-amp/lib/rpmsg/rpmsg.c @@ -7,6 +7,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include #include #include @@ -141,7 +142,7 @@ int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags) ns_msg.flags = flags; ns_msg.addr = ept->addr; - strncpy(ns_msg.name, ept->name, sizeof(ns_msg.name)); + (void)strlcpy(ns_msg.name, ept->name, sizeof(ns_msg.name)); ret = rpmsg_send_offchannel_raw(ept, ept->addr, RPMSG_NS_EPT_ADDR, &ns_msg, sizeof(ns_msg), true); @@ -305,7 +306,7 @@ void rpmsg_register_endpoint(struct rpmsg_device *rdev, rpmsg_ept_cb cb, rpmsg_ns_unbind_cb ns_unbind_cb, void *priv) { - strncpy(ept->name, name ? name : "", sizeof(ept->name)); + (void)strlcpy(ept->name, name ? name : "", sizeof(ept->name)); ept->refcnt = 1; ept->addr = src; ept->dest_addr = dest;