From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27F06C433E0 for ; Thu, 18 Mar 2021 14:13:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F20AD64EF9 for ; Thu, 18 Mar 2021 14:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231555AbhCRONV (ORCPT ); Thu, 18 Mar 2021 10:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231636AbhCRONQ (ORCPT ); Thu, 18 Mar 2021 10:13:16 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6ADCC06174A; Thu, 18 Mar 2021 07:13:16 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id AFA041F45F65 Subject: Re: [PATCH v2 3/4] fs: unicode: Use strscpy() instead of strncpy() To: krisman@collabora.com, jaegeuk@kernel.org, yuchao0@huawei.com, tytso@mit.edu, adilger.kernel@dilger.ca, drosen@google.com, ebiggers@google.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel@collabora.com, andre.almeida@collabora.com, kernel test robot References: <20210318133305.316564-1-shreeya.patel@collabora.com> <20210318133305.316564-4-shreeya.patel@collabora.com> From: Shreeya Patel Message-ID: Date: Thu, 18 Mar 2021 19:43:08 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210318133305.316564-4-shreeya.patel@collabora.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Reported-by: kernel test robot > --- > 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;