Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4479014pxf; Tue, 23 Mar 2021 11:34:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqL2qXJ/fOy1L+dDUhmFDlCI1UaQJr9S1vP18DTqdwYnpO1n/1Rb1YD2Jt4SSNB17xBlxR X-Received: by 2002:a17:906:6817:: with SMTP id k23mr6120381ejr.6.1616524442395; Tue, 23 Mar 2021 11:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616524442; cv=none; d=google.com; s=arc-20160816; b=vCU3Ch2uNYGJMsrQdfQEvJnimxPluAqB2xprdj1yPhV98qt8P7R6cHjssyNIbI+GwF 2xJgSG3EkdVHhIUpX44xgBL0wI0z9mgtUbQvJ7DXXNvV4UxYuzdvcKLDL08ajJ11dcnw XtbEosqyFhPVFpfMfDQi5UBpiv3oRHdie6qVuBX+PeCGxxq50uPQX5xgZFUShalqWVDm PGUPiDeP7oIducf2XtEIn1lj9BPgoAqjMBDDIvvOefHGURRy6wBhV+7xOw3ya2RenuBM u9ccmfQPtyjGvYrwyyJupXoXuUq44CojxyaIFjlFAEhh3zt/KPPcqjQcVBMf8FqjfSUQ GZeQ== 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=SzT9ktdwXZE0eVOLVEEEH8492frG/oDBRrb4LhS4vlk=; b=QbVYNXrRuNQZmdsP2LPwAoqlgvcUb0k63hxkBtHYdmZOeqos0AgISdoBfKJSbxm8OG i7DjXMSenpxixS1tkZnsSOZavskSJ1r4jbJV0Zq3CHqFRH4gIGhJe96KKaKDxQoBV/5y lBd79aS5ynGnjBUS1j/WZEOE4M1b3TC6t6JE2t5wf33SHgJvfiI07CEBHlRzSWUZQkPT 2oDbOJmsrbsGnJLGjnAno/jw3m11lu5MMhpUAnZhI+HMuXZ8sN1qn1l4J1DkSkW9rABr A5cz+nlcoV6biLPbz0ZagxwAw0TrMEJyjXvju2xXy7jksfHyJQ+DbzIfqQa1tK+Yq9ts KfRQ== 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 gz11si15568541ejc.745.2021.03.23.11.33.35; Tue, 23 Mar 2021 11:34:02 -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 S231553AbhCWSdD (ORCPT + 99 others); Tue, 23 Mar 2021 14:33:03 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53220 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231380AbhCWScm (ORCPT ); Tue, 23 Mar 2021 14:32:42 -0400 Received: from localhost.localdomain (unknown [IPv6:2401:4900:5170:240f:f606:c194:2a1c:c147]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shreeya) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 82FE31F44A66; Tue, 23 Mar 2021 18:32:32 +0000 (GMT) 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 v3 1/5] fs: unicode: Use strscpy() instead of strncpy() Date: Wed, 24 Mar 2021 00:01:57 +0530 Message-Id: <20210323183201.812944-2-shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323183201.812944-1-shreeya.patel@collabora.com> References: <20210323183201.812944-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) Signed-off-by: Shreeya Patel Reported-by: kernel test robot --- Changes in v3 - Return error if strscpy() returns value < 0 Changes in v2 - Resolve warning of -Wstringop-truncation reported by kernel test robot. fs/unicode/utf8-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index dc25823bf..706f086bb 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -180,7 +180,10 @@ static int utf8_parse_version(const char *version, unsigned int *maj, {0, NULL} }; - strncpy(version_string, version, sizeof(version_string)); + int ret = strscpy(version_string, version, sizeof(version_string)); + + if (ret < 0) + return ret; if (match_token(version_string, token, args) != 1) return -EINVAL; -- 2.24.3 (Apple Git-128)