Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1666707pxy; Fri, 23 Apr 2021 13:52:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEcZXMmEMFGCClSunWHbedYiuPYACKiNZAe1mcHw0XdsspVXNqmQjUoT7g7j1wiBMp9Tgc X-Received: by 2002:a63:3244:: with SMTP id y65mr5709058pgy.197.1619211141305; Fri, 23 Apr 2021 13:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619211141; cv=none; d=google.com; s=arc-20160816; b=k9YIsC9C15hUumj7lZ2xFBzd9NFoPGkTkeUmYWDgUHkCUQfSHSWXQnuxpFvrzbhsS8 w8sr1D68gHcMwkSCI5WTPX2YJVZAF49kbS1Jh5AptATUwNyUSoiXOkxjpAyDMBRfL2j0 N+FtgX5SIog2aema076kTr3+JBfBP6qvMq46tmGcpK+5dRFdgrTmTSrNIj9JGR/SZfvp /JrABK5CnMNx6sUTZOj54MN9+NiYqzUgMfjX4WT4SNOiUCVi7N5JxL2nfC5/I34g+h24 hvFi0TNVzPNL6l9hTKKZSpaWhBThrP49Zs0ISYsDYafgi2+yRZJJy6t7Ypb0zYhVEFBT fLJA== 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=vJA8UupobNW9INO4X6eIV+mC+FGSQvTp792YW6+E8Jc=; b=pDTSCT5SGmR1GSfcJetJYEgD8vqWSTD74OQHBJmqqltGfNPSwKjmQzqkiHNwTVKVyI 88/23LnKY/vbCSJoODqmUxtgRwnejcvlJSj1AzQNHbxPNubpOdLurOy5OdzGaIRWGltZ dxTMBYStd0P4ZDZ/g0zrsXUlPsavvO7ZbAXXdY/0NkPo3Of7b78qYedPK1sI9j5v0Isn kwPGxq4ODkbyerpFVT6dNinDO7UmPPgoj5yuosByL8ldoK7JSZKmwyAFh5MG1FdoXj6u QqNE32bcRGkpqzc+3oXQr3MABBupDRfumt6cgQGYNja0VtdRPaC2WRP7TkupX7rk0RhG cr7A== 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 n192si7792589pfd.34.2021.04.23.13.52.06; Fri, 23 Apr 2021 13:52:21 -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 S244012AbhDWUwh (ORCPT + 99 others); Fri, 23 Apr 2021 16:52:37 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:41382 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243974AbhDWUwd (ORCPT ); Fri, 23 Apr 2021 16:52:33 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id 74E8E1F41F63 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 v8 1/4] fs: unicode: Use strscpy() instead of strncpy() Date: Sat, 24 Apr 2021 02:21:33 +0530 Message-Id: <20210423205136.1015456-2-shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210423205136.1015456-1-shreeya.patel@collabora.com> References: <20210423205136.1015456-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 if source string is longer than the destination size. strscpy() returns -E2BIG error code in case the source string doesn't fit into the destination. Hence, use strscpy() and return an error for overly-long strings instead of creating a non-null-terminated string with 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 --- Changes in v8 - Improve the commit message to decribe about how overly-long strings are handled. 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.2