Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3862418pxf; Mon, 29 Mar 2021 13:44:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiXNNH5h3Rn66yMMahMIq/O8swVlCLQDFU1a9+A8pPzghtrb0KLBI6v5xvmK9SaHb7hSD+ X-Received: by 2002:a05:6402:704:: with SMTP id w4mr31420096edx.175.1617050653911; Mon, 29 Mar 2021 13:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617050653; cv=none; d=google.com; s=arc-20160816; b=XD5HpmjuXWgZMlCSG7/UMhs1okpsij5ec0JSGZuJ6We7/e5E96d8yj29SH/zhGko/w U6uTbz/QBSWk4LGFBHUCsdUtCzvMOskd/d43tfGsd6shXY2NXEyt4GqMwx374LUn2gEl myMtN/42ntaNH23x0zojnQr8o6f3GPEfXfwMe5Ut2vy6OfBFahZgPSAdCc0dK2wK+Jlb P0G1V3728p4jVRNW0jqbL2TX3CZubsuMT2ZygpVaHhFJ4wlLXU9ZmQL5dP6XzeIekGvy 9yk0GYutpLb54dhubA0mDee9Tr+rtECOX2VDcOjiGeryezQlr3ndby439jBeAvspvHee HbEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Bf8bZPFlrxSC34lBI2920hDN93+sFO1N6H2UO8cuQeg=; b=T4vQi54gOi8WpZdiycABeb8PPVrwPFVslc0PDGTkE6R2VX2kCUybDvG14eOK6h8vfa 0V1kAVI8pYqqibrak/APcN4L2kTk742h0Pe8sEyusrBoSJKfRmUvRWyPf6BrY9Fam8xo 18RaPvZCzkt1J0nGJk/dkxidLrsHXlcFTc5wjgUz7B3xBEjl1pJFDF2zzbaeglEmRywx 67jDQ41WQOq+6rxTsd0ZcnV/MXXeOJixM9ikSo9HYPIxXNKPIIt5D3Ei3UniYCKdxFoJ cbMg1vdVbbuE4O0ySamLdlqRiE0c4PKefa9dV94aip6IJwRgpOFssX9SnXMYPBqREMw9 JQ7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 h12si14349138ejx.570.2021.03.29.13.43.49; Mon, 29 Mar 2021 13:44:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 S231417AbhC2UnQ (ORCPT + 99 others); Mon, 29 Mar 2021 16:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbhC2UnE (ORCPT ); Mon, 29 Mar 2021 16:43:04 -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 0FAE1C061574; Mon, 29 Mar 2021 13:43:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id D5AAC1F454FD From: Shreeya Patel To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org, chao@kernel.org, krisman@collabora.com, ebiggers@google.com, drosen@google.com, ebiggers@kernel.org, yuchao0@huawei.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, kernel@collabora.com, andre.almeida@collabora.com, kernel test robot Subject: [PATCH v5 1/4] fs: unicode: Use strscpy() instead of strncpy() Date: Tue, 30 Mar 2021 02:12:37 +0530 Message-Id: <20210329204240.359184-2-shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210329204240.359184-1-shreeya.patel@collabora.com> References: <20210329204240.359184-1-shreeya.patel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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(). Fixes: 9d53690f0d4e5 (unicode: implement higher level API for string handling) Acked-by: Gabriel Krisman Bertazi Signed-off-by: Shreeya Patel Reported-by: kernel test robot --- fs/unicode/utf8-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index dc25823bfed9..f9e6a2718aba 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -179,8 +179,10 @@ static int utf8_parse_version(const char *version, unsigned int *maj, {1, "%d.%d.%d"}, {0, NULL} }; + int ret = strscpy(version_string, version, sizeof(version_string)); - strncpy(version_string, version, sizeof(version_string)); + if (ret < 0) + return ret; if (match_token(version_string, token, args) != 1) return -EINVAL; -- 2.30.1