[PATCH] tools/x86/kcpuid: Replace deprecated strncpy() with strscpy()

feng.wei8@zte.com.cn posted 1 patch 9 months ago
tools/arch/x86/kcpuid/kcpuid.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] tools/x86/kcpuid: Replace deprecated strncpy() with strscpy()
Posted by feng.wei8@zte.com.cn 9 months ago
From: FengWei <feng.wei8@zte.com.cn>

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>
---
 tools/arch/x86/kcpuid/kcpuid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 1b25c0a95d3f..23a8fde2e203 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -312,8 +312,7 @@ static int parse_line(char *line)
 	if (line[0] == '#' || line[0] == '\n')
 		return 0;

-	strncpy(buffer, line, 511);
-	buffer[511] = 0;
+	strscpy(buffer, line, 511);
 	str = buffer;
 	for (i = 0; i < 5; i++) {
 		tokens[i] = strtok(str, ",");
-- 
2.25.1
Re: [PATCH] tools/x86/kcpuid: Replace deprecated strncpy() with strscpy()
Posted by Jiri Slaby 9 months ago
On 17. 03. 25, 8:32, feng.wei8@zte.com.cn wrote:
> From: FengWei <feng.wei8@zte.com.cn>
> 
> 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>
> ---
>   tools/arch/x86/kcpuid/kcpuid.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
> index 1b25c0a95d3f..23a8fde2e203 100644
> --- a/tools/arch/x86/kcpuid/kcpuid.c
> +++ b/tools/arch/x86/kcpuid/kcpuid.c
> @@ -312,8 +312,7 @@ static int parse_line(char *line)
>   	if (line[0] == '#' || line[0] == '\n')
>   		return 0;
> 
> -	strncpy(buffer, line, 511);
> -	buffer[511] = 0;
> +	strscpy(buffer, line, 511);

Mind you this is userspace?

-- 
js
suse labs