Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()

Replace sprintf() with the safer variant scnprintf() and use its return
value instead of calculating the string length again using strlen().

Use strscpy() instead of the deprecated strcpy().

No functional changes intended.

Link: https://github.com/KSPP/linux/issues/88
Link: https://lkml.kernel.org/r/20250521121840.5653-1-thorsten.blum@linux.dev
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: guoweikang <guoweikang.kernel@gmail.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Thorsten Blum and committed by
Andrew Morton
08e2153d 85df0d50

+7 -4
+7 -4
arch/alpha/kernel/core_marvel.c
··· 17 17 #include <linux/vmalloc.h> 18 18 #include <linux/mc146818rtc.h> 19 19 #include <linux/rtc.h> 20 + #include <linux/string.h> 20 21 #include <linux/module.h> 21 22 #include <linux/memblock.h> 22 23 ··· 80 79 { 81 80 char tmp[80]; 82 81 char *name; 83 - 84 - sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port); 85 - name = memblock_alloc_or_panic(strlen(tmp) + 1, SMP_CACHE_BYTES); 86 - strcpy(name, tmp); 82 + size_t sz; 83 + 84 + sz = scnprintf(tmp, sizeof(tmp), "PCI %s PE %d PORT %d", str, pe, port); 85 + sz += 1; /* NUL terminator */ 86 + name = memblock_alloc_or_panic(sz, SMP_CACHE_BYTES); 87 + strscpy(name, tmp, sz); 87 88 88 89 return name; 89 90 }