[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f6bb5ec3-da94-ae9a-4ac4-e39038b42cb3@collabora.com>
Date: Thu, 18 Mar 2021 19:43:08 +0530
From: Shreeya Patel <shreeya.patel@...labora.com>
To: krisman@...labora.com, jaegeuk@...nel.org, yuchao0@...wei.com,
tytso@....edu, adilger.kernel@...ger.ca, drosen@...gle.com,
ebiggers@...gle.com
Cc: linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
kernel@...labora.com, andre.almeida@...labora.com,
kernel test robot <lkp@...el.com>
Subject: Re: [PATCH v2 3/4] fs: unicode: Use strscpy() instead of strncpy()
On 18/03/21 7:03 pm, Shreeya Patel wrote:
> Following warning was reported by Kernel Test Robot.
>
> In function 'utf8_parse_version',
> inlined from 'utf8_load' at fs/unicode/utf8mod.c:195:7:
>>> fs/unicode/utf8mod.c:175:2: warning: 'strncpy' specified bound 12 equals
> destination size [-Wstringop-truncation]
> 175 | strncpy(version_string, version, sizeof(version_string));
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The -Wstringop-truncation warning highlights the unintended
> uses of the strncpy function that truncate the terminating NULL
> character from the source string.
> Unlike strncpy(), strscpy() always null-terminates the destination string,
> hence use strscpy() instead of strncpy().
Not sure if strscpy is preferable. Just found this article
https://lwn.net/Articles/659214/
Should I go for memcpy instead?
>
> Signed-off-by: Shreeya Patel <shreeya.patel@...labora.com>
> Reported-by: kernel test robot <lkp@...el.com>
> ---
> Changes in v2
> - Resolve warning of -Wstringop-truncation reported by
> kernel test robot.
>
> fs/unicode/unicode-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/unicode/unicode-core.c b/fs/unicode/unicode-core.c
> index d5f09e022ac5..287a8a48836c 100644
> --- a/fs/unicode/unicode-core.c
> +++ b/fs/unicode/unicode-core.c
> @@ -179,7 +179,7 @@ static int unicode_parse_version(const char *version, unsigned int *maj,
> {0, NULL}
> };
>
> - strncpy(version_string, version, sizeof(version_string));
> + strscpy(version_string, version, sizeof(version_string));
>
> if (match_token(version_string, token, args) != 1)
> return -EINVAL;
Powered by blists - more mailing lists