[PATCH] sprint_symbol: Replace strcpy with memmove to handle potential overlap

From: liujinlong
Date: Tue Jun 04 2024 - 00:42:43 EST


In the function __sprint_symbol, replace strcpy with memmove to ensure
correct behavior even if the source and destination buffers overlap.
This change prevents potential undefined behavior flagged by recent
compilers as [-Werror=restrict].

Reported-by: k2ci <kernel-bot@xxxxxxxxxx>
Signed-off-by: liujinlong <liujinlong@xxxxxxxxxx>
---
kernel/kallsyms.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 22ea19a36e6e..3c3a77fcd020 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -489,7 +489,7 @@ static int __sprint_symbol(char *buffer, unsigned long address,
return sprintf(buffer, "0x%lx", address - symbol_offset);

if (name != buffer)
- strcpy(buffer, name);
+ memmove(buffer, name, strlen(name) + 1);
len = strlen(buffer);
offset -= symbol_offset;

--
2.17.1