Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp572631pxf; Thu, 18 Mar 2021 07:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTBRazm8khXYpIq2P9tSK1TNdGDtfq4w0yKFoLKv4Em4njRd4bIbebVoiiPCYDNo3S/fel X-Received: by 2002:a17:906:bccc:: with SMTP id lw12mr40671923ejb.268.1616077186616; Thu, 18 Mar 2021 07:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616077186; cv=none; d=google.com; s=arc-20160816; b=L+19xpU9maUmmLqcFhr0itqxDbzBTM95F8SwS8cfs72imFKlBA7J1jNBcDq1xbeg67 egVrszrwgap5pQnVs9mFl9LYTKflw7LLfa6sv4BkCYVnaTyoubtnaagd5hSCepM0d/PC jZNVAsYHXnciVuGKtMSWzjSb4uDqfV0SaQonQmj6PzSvP9Tf+J0iwPpxQIn5D9IioBeE 9iNhH1LyWxNxvK5Vj1fKfLaigVIhYo0H961N7Lc49DQSJehIYqFquU8mu4YbDOBxStFN Y/S50QB0LPpnziSOLYswqEO/bVktveYm5yy4MTGHRh0U1j6V5RfANBstBjPfOQCb6QHL M8Zg== 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=XSx937vRYAgcHdP3pm4n92Pa1/+X8e8W1mDhLtAb4hA=; b=FNHvJ6Uto2uSJ2GBoDVHXRLu5uKEuHXCc4jKpNJQuSIoxEMgAnfZnl9yUtwcW+KWyC eGrDrj8CCI2CmSS7Z3GB32FLBAipXdveET8kCvtNWgAddnhYtXdqgeEMO4SMf4Pz1CyD tScidZQP6hVCiZkmA4H4uH8qSLJ/J3v9hRvLz0qHRcWec4xaKFBwetJGvywF1r2tYQPm C8KX13a84QjNtzFNGcpikgS8JD1FgMX/7Cuwubmjt0ivVa0CpepQb6ClihEsffRrtFU5 FQJekbXBKxdzNFusm1JJRkx2YHdr+m0SJop8dyoyA2XOxlQHWLmv78Y3xBN4mTbEKOa1 ByJQ== 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 ec10si1748344ejb.386.2021.03.18.07.19.23; Thu, 18 Mar 2021 07:19:46 -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 S231495AbhCRONV (ORCPT + 99 others); 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;