Skip to content

Commit

Permalink
lib: rpmsg: replace strncpy with internal strlcpy
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit e83acc98ad18f27bd1c12de808aaed84a0091791)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
  • Loading branch information
arnopo authored and tomi-font committed Sep 30, 2024
1 parent 711d4b0 commit 8e5a760
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions open-amp/lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <internal/string.h>
#include <openamp/rpmsg.h>
#include <metal/alloc.h>

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8e5a760

Please sign in to comment.