Skip to content

Commit

Permalink
lib: remoteproc: replace strncpy with internal safe_strcpy
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 safe_strcpy() function, which guarantees null-termination of the
destination string but also access only in buffer memory ranges.

Note: (void)safe_strcpy(...) indicates that the return value is
intentionally ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
  • Loading branch information
arnopo committed Oct 14, 2024
1 parent bd2a849 commit f5fc265
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/remoteproc/remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <internal/string.h>
#include <metal/alloc.h>
#include <metal/log.h>
#include <metal/utilities.h>
Expand Down Expand Up @@ -306,7 +307,7 @@ void remoteproc_init_mem(struct remoteproc_mem *mem, const char *name,
if (!mem || !io || size == 0)
return;
if (name)
strncpy(mem->name, name, sizeof(mem->name));
(void)safe_strcpy(mem->name, sizeof(mem->name), name, sizeof(name));
else
mem->name[0] = 0;
mem->pa = pa;
Expand Down

0 comments on commit f5fc265

Please sign in to comment.