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=unavailable 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 89F72C433E0 for ; Fri, 19 Mar 2021 10:33:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E38364F6E for ; Fri, 19 Mar 2021 10:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbhCSKcm (ORCPT ); Fri, 19 Mar 2021 06:32:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbhCSKcO (ORCPT ); Fri, 19 Mar 2021 06:32:14 -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 DC8BCC06174A; Fri, 19 Mar 2021 03:32:13 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id 83A7D1F466DF Subject: Re: [PATCH v2 3/4] fs: unicode: Use strscpy() instead of strncpy() To: Eric Biggers Cc: krisman@collabora.com, jaegeuk@kernel.org, yuchao0@huawei.com, tytso@mit.edu, adilger.kernel@dilger.ca, drosen@google.com, 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: Fri, 19 Mar 2021 16:02:05 +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: 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 19/03/21 2:33 am, Eric Biggers wrote: > On Thu, Mar 18, 2021 at 07:03:04PM +0530, 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(). >> >> 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)); >> > Shouldn't unicode_parse_version() return an error if the string gets truncated > here? I.e. check if strscpy() returns < 0. > > Also, this is a "fix" (though one that doesn't currently matter, since 'version' > is currently always shorter than sizeof(version_string)), so it should go first > in the series and have a Fixes tag. Thanks Eric, will send v3 for it. > > - Eric