diff mbox series

MIPS: Loongson2ef: Replace deprecated strncpy() with strscpy()

Message ID 20250224215451.195727-2-thorsten.blum@linux.dev (mailing list archive)
State In Next
Commit 1bea9ab46d9f9871b71b078192699fc94287fcc4
Headers show
Series MIPS: Loongson2ef: Replace deprecated strncpy() with strscpy() | expand

Commit Message

Thorsten Blum Feb. 24, 2025, 9:54 p.m. UTC
strncpy() is deprecated for NUL-terminated destination buffers. Use
strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/mips/loongson2ef/common/machtype.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Thomas Bogendoerfer Feb. 27, 2025, 10:04 a.m. UTC | #1
On Mon, Feb 24, 2025 at 10:54:50PM +0100, Thorsten Blum wrote:
> strncpy() is deprecated for NUL-terminated destination buffers. Use
> strscpy() instead and remove the manual NUL-termination.
> 
> Compile-tested only.
> 
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/mips/loongson2ef/common/machtype.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/mips/loongson2ef/common/machtype.c b/arch/mips/loongson2ef/common/machtype.c
> index 82f6de49f20f..e635e66d2e6c 100644
> --- a/arch/mips/loongson2ef/common/machtype.c
> +++ b/arch/mips/loongson2ef/common/machtype.c
> @@ -48,8 +48,7 @@ void __init prom_init_machtype(void)
>  		return;
>  	}
>  	p += strlen("machtype=");
> -	strncpy(str, p, MACHTYPE_LEN);
> -	str[MACHTYPE_LEN] = '\0';
> +	strscpy(str, p);
>  	p = strstr(str, " ");
>  	if (p)
>  		*p = '\0';
> -- 
> 2.48.1

applied to mips-next.

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/loongson2ef/common/machtype.c b/arch/mips/loongson2ef/common/machtype.c
index 82f6de49f20f..e635e66d2e6c 100644
--- a/arch/mips/loongson2ef/common/machtype.c
+++ b/arch/mips/loongson2ef/common/machtype.c
@@ -48,8 +48,7 @@  void __init prom_init_machtype(void)
 		return;
 	}
 	p += strlen("machtype=");
-	strncpy(str, p, MACHTYPE_LEN);
-	str[MACHTYPE_LEN] = '\0';
+	strscpy(str, p);
 	p = strstr(str, " ");
 	if (p)
 		*p = '\0';