Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1275293pxf; Fri, 19 Mar 2021 03:33:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlH8PsTtpHYN7Q7ewSAvJwP8wXQ6LZU1JHI9xmNfRoYfNveyjOpL7X0pWoIlpjHSCVUhNJ X-Received: by 2002:a17:906:35cf:: with SMTP id p15mr3488246ejb.379.1616150039727; Fri, 19 Mar 2021 03:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616150039; cv=none; d=google.com; s=arc-20160816; b=n0MWEbOsXrcdAm6rlzu8rRA/wFOqasUStEowYklThLN8dHkA+SNnqgDWP6uTVCnLAp r5xB1hygfV6xOg/H2kKtfqWmdMJ4xAfOsIuUpdol4KaL04VydfsuSV89ohS49KQnbuYP VbELM3yx/PrBWO7tO4FjC7x6VFWs3xGI01puZgxv9CfHl+vwuWPGGVE/IcbmJVdjP+nf O1zfg7OGZhSxoS8tNsdtbaRc7XJ47MIHUP1z11QzC4BWBpnkOLbe+YLMwSOSM7D2xYiQ xqaByhvQCj3cKLOVGF/hfpdRo6ZQB7lUkil1ZPPbuiyGcCpXp0IZnsak1SC3cC0WhOOk MhBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=aTkuX6oaqFkl2/cTLTDH1PkUxDGzu5Htqac8T0FXmXE=; b=G1OMG3DveP4keO3Ugfdg4Tg1OUO1ru8SBmoutOvkE8sI0CZ491htgrfVbmCc2+uELJ GON4YMazgH7nAfGk+osMmwG4XA5olGS7lT+5FTTWFkgzxoz8Xc9/7TqX/s9od+f9s/Vq wJ2VqQh8XtkSoMWTSKfIeigfRkQlzHeXGQ5rL8NHbIP+H+SOtOYBRnV1HCcYB4/VVKNS eyQ/PQrh/nEXRhErjVzf7BnBbpOpy+q+oQY8uaX+fdrPn0P4wBVE0cBVTEqwEmxHYdzi 9eLP2SWpSR3xYOKH6bBHGbFNvRSvAfmV6IOCwoOLjTzguN26pYYU9aNlf8UDr2VpWudS KFxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z24si3539716ejx.462.2021.03.19.03.33.37; Fri, 19 Mar 2021 03:33:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbhCSKcl (ORCPT + 99 others); Fri, 19 Mar 2021 06:32:41 -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