diff mbox series

kconfig: Replace strncpy() with strscpy()

Message ID 20250317152257605EN-VIC5_IyrowJu481BsZ@zte.com.cn (mailing list archive)
State New
Headers show
Series kconfig: Replace strncpy() with strscpy() | expand

Commit Message

feng.wei8@zte.com.cn March 17, 2025, 7:22 a.m. UTC
From: FengWei <feng.wei8@zte.com.cn>

supplemented:
strncpy() is deprecated for NUL-terminated destination buffers. Use
strscpy() instead and remove the manual NUL-termination.

Signed-off-by: FengWei <feng.wei8@zte.com.cn>
---
 scripts/kconfig/confdata.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Jiri Slaby March 17, 2025, 8:50 a.m. UTC | #1
On 17. 03. 25, 8:22, feng.wei8@zte.com.cn wrote:
> From: FengWei <feng.wei8@zte.com.cn>
> 
> supplemented:
> strncpy() is deprecated for NUL-terminated destination buffers. Use
> strscpy() instead and remove the manual NUL-termination.
> 
> Signed-off-by: FengWei <feng.wei8@zte.com.cn>
> ---
>   scripts/kconfig/confdata.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index ac95661a1c9d..e547ce003f00 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -970,8 +970,7 @@ static int conf_touch_deps(void)
>   	if (depfile_prefix_len + 1 > sizeof(depfile_path))
>   		return -1;
> 
> -	strncpy(depfile_path, name, depfile_prefix_len);
> -	depfile_path[depfile_prefix_len] = 0;
> +	strscpy(depfile_path, name, depfile_prefix_len);

Are you aware this is userspace?

So: do you even compile-test all this?
diff mbox series

Patch

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index ac95661a1c9d..e547ce003f00 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -970,8 +970,7 @@  static int conf_touch_deps(void)
 	if (depfile_prefix_len + 1 > sizeof(depfile_path))
 		return -1;

-	strncpy(depfile_path, name, depfile_prefix_len);
-	depfile_path[depfile_prefix_len] = 0;
+	strscpy(depfile_path, name, depfile_prefix_len);

 	conf_read_simple(name, S_DEF_AUTO);