public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/boot: replace strncpy() with strscpy()
@ 2025-04-02 23:14 Amir Mohammad Jahangirzad
  2025-04-09 13:31 ` Heiko Carstens
  0 siblings, 1 reply; 2+ messages in thread
From: Amir Mohammad Jahangirzad @ 2025-04-02 23:14 UTC (permalink / raw)
  To: hca, gor, agordeev
  Cc: borntraeger, svens, linux-s390, linux-kernel,
	Amir Mohammad Jahangirzad

From: "Amir Mohammad Jahangirzad" <a.jahangirzad@gmail.com>

strncpy() is deprecated for use on NUL-terminated destination strings
as it doesn't guarantee NUL-termination when the source string length
exceeds the destination buffer size. strscpy() is a safer alternative
as it always NUL-terminates the destination and returns the number of
characters copied (excluding the NUL).

Replace strncpy() with strscpy() for copying the bootdebug_filter value,
using sizeof(bootdebug_filter) rather than sizeof()-1 since strscpy()
takes the full buffer size as parameter.


Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Amir Mohammad Jahangirzad <a.jahangirzad@gmail.com>
---
 arch/s390/boot/ipl_parm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/boot/ipl_parm.c b/arch/s390/boot/ipl_parm.c
index d04e9b89d14a..8b153f7b4112 100644
--- a/arch/s390/boot/ipl_parm.c
+++ b/arch/s390/boot/ipl_parm.c
@@ -309,7 +309,7 @@ void parse_boot_command_line(void)
 		if (!strcmp(param, "bootdebug")) {
 			bootdebug = true;
 			if (val)
-				strncpy(bootdebug_filter, val, sizeof(bootdebug_filter) - 1);
+				strscpy(bootdebug_filter, val, sizeof(bootdebug_filter));
 		}
 		if (!strcmp(param, "quiet"))
 			boot_console_loglevel = CONSOLE_LOGLEVEL_QUIET;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] s390/boot: replace strncpy() with strscpy()
  2025-04-02 23:14 [PATCH] s390/boot: replace strncpy() with strscpy() Amir Mohammad Jahangirzad
@ 2025-04-09 13:31 ` Heiko Carstens
  0 siblings, 0 replies; 2+ messages in thread
From: Heiko Carstens @ 2025-04-09 13:31 UTC (permalink / raw)
  To: Amir Mohammad Jahangirzad
  Cc: gor, agordeev, borntraeger, svens, linux-s390, linux-kernel

On Thu, Apr 03, 2025 at 02:44:34AM +0330, Amir Mohammad Jahangirzad wrote:
> From: "Amir Mohammad Jahangirzad" <a.jahangirzad@gmail.com>
> 
> strncpy() is deprecated for use on NUL-terminated destination strings
> as it doesn't guarantee NUL-termination when the source string length
> exceeds the destination buffer size. strscpy() is a safer alternative
> as it always NUL-terminates the destination and returns the number of
> characters copied (excluding the NUL).
> 
> Replace strncpy() with strscpy() for copying the bootdebug_filter value,
> using sizeof(bootdebug_filter) rather than sizeof()-1 since strscpy()
> takes the full buffer size as parameter.
> 
> 
> Link: https://github.com/KSPP/linux/issues/90
> Signed-off-by: Amir Mohammad Jahangirzad <a.jahangirzad@gmail.com>
> ---
>  arch/s390/boot/ipl_parm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

You could have at least compile tested this before sending.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-09 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02 23:14 [PATCH] s390/boot: replace strncpy() with strscpy() Amir Mohammad Jahangirzad
2025-04-09 13:31 ` Heiko Carstens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox