Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp884282pxf; Wed, 7 Apr 2021 14:06:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxBhUrtR6mMKWQrDxp0cA9oho30QMKRLsKn27M0W3ovPDhbok0WSUBUaKGAxvX2hYQDh4p X-Received: by 2002:a05:6e02:15c1:: with SMTP id q1mr4302632ilu.151.1617829593908; Wed, 07 Apr 2021 14:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617829593; cv=none; d=google.com; s=arc-20160816; b=a5LccGB3CCjZlJ90tPxKPi5/SY9D/E+sEyWjJo8+xr8wr8v8mzt5UYotK0iml60+pQ 2bdm1ogKjXB8Zm7nTGXQYsFawWeLF4Mcr41dbi5Wi3CLFKS/uMEdUsqypBVnecoYJqzP xTdl4yGEbcRBoS/nk3qBRr0YW3gHkJ6MSck8jllfuzEHqnfYTgQ1M4xnHmUz682pEc7t MAEgOaaH+pxLzqKYR5f+pJGaCzREDlvM3kwtkbXh537tuyfMQ7w7gIq1rdDzl2A6l/rn Kpjoy6kjvgMWTcmzqXOvKSOiQsR5iw/Y26iIJrzpSBO768piYuf4ZWwsXFU/emhBt0Ff CptA== 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=hYrYhuqXG63JUEG+jqrMWseiue4iJlnD52qMexmQ5aM=; b=TktLLGO0ySAp35fvUk4ymUeQuYxcZbFzaFc3HHFpnKRUAsfRrU1iza2Lw8zxjoKyen mXJxMdUZEZLxF8NjkxzJL7Qr03YBLPyYvQn4NgisLBExDNFPho/mvUs7tVc2WxMWL2kU O/Ry8rtFzzWMyQeG9mQrDNg/9UebIT3unfE6rcZdGbFAeRS3LLqGO31JXEQmiBCWaAb0 zV/63Whv4n22EsPuoql7Nvi8RlcuGq16L9lHL36TUkqWvuewrEDIJtVg3aeXMzFSsgiV vfxa7kd+KfeVxy1qQqLg8d8k4kE0JrWRhKPSWZHZaKBe0uTJ+xdoAI//FQVf0LhHVX90 8S7Q== 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 p31si22569488jal.19.2021.04.07.14.06.19; Wed, 07 Apr 2021 14:06:33 -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 S1348765AbhDGOti (ORCPT + 99 others); Wed, 7 Apr 2021 10:49:38 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:60854 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353180AbhDGOt3 (ORCPT ); Wed, 7 Apr 2021 10:49:29 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id 2D1B31F45087 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 v7 1/4] fs: unicode: Use strscpy() instead of strncpy() Date: Wed, 7 Apr 2021 20:18:42 +0530 Message-Id: <20210407144845.53266-2-shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407144845.53266-1-shreeya.patel@collabora.com> References: <20210407144845.53266-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.2