Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2000819lqe; Tue, 9 Apr 2024 07:04:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpP1NJXKUvO46u/mnTmLQ+oXha1au8F0MO4AkGZPV9JBnxYrXAdWUzOd4XyeOFqWX7JSxtlvd0T2axp5wGp0j+D+PvslvCel0qFjEwyQ== X-Google-Smtp-Source: AGHT+IEJiY2TU6wCfUEE6uCMUlspztUPnZYghZyuCKYx7LLxYGIgkckJikFTuc2xNiEMiaH2TjtG X-Received: by 2002:a17:906:f584:b0:a51:dd18:bd1e with SMTP id cm4-20020a170906f58400b00a51dd18bd1emr4005855ejd.12.1712671446538; Tue, 09 Apr 2024 07:04:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712671446; cv=pass; d=google.com; s=arc-20160816; b=fiMcwVHzGDfHMx5b5qnZOSg2P4KtSOm/Ww/71LcBbR5RC2fTe3eX96F+MzOVPZAhlp NupTRQnUkvQUz1GrlK5FEXDINFi3uQvgpNTvxffqtKvROkX+grRds48p2k1goKYvUMug d1NSGV6lIsFbMVku3ng2tKENnproS+P+XSZMc50JoraxiVnsbpHWJciUauied28HQm+Z UyWYsIervaXI6035Dvcmry+fiSvnqvYOwGbtZC/ZqxzxCOXFt6tgpUacs9bOPYn2KxDl 5EY+h1SFIMei0xiIBpfN220e0HBAtpzuyhZwHhXEgj3RYKN4xOMKJC+MaGCfC0mbViP1 cD1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EyGKaVrqF9sMEQbwnFuTNScJgARVs5b2YqLdQkmN+XI=; fh=d7NWZzVMBe+YtQ0AhDOD1J4yzuU7RP8mHyX/yJVFxsg=; b=OY7R7AOTITz5HNJhZtaUv1sHZlnsw+i2eNkcw5B/qzrT/ByICD66KSASGP3SZpf90J yFCAjLFi+KeYSZUkzX3Y0f7PIAvD0tRHBkuRnln25JXDcujx3JF0bs8CS1g4ws7IL/2k Y+yuQDva9MKNSNKI8gJE1KHL13+N0+ap9LQcCCOdkZ9O0IJvqGGM520zBfFetOcY/hMI qJSQUiXDVayXZ6XyKgT+imoOgpChakbqrtB7WlyTahRjO4lsmykZ2rJbsxH+xcNc88uO JoCTVwTc7XyAlXzEWTZbquYWWVVynVGY+ytRXIYkoy1F8Pz70pdoK39torLPEuFtSrHA VMbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=seYFDBBN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-137049-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137049-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hr17-20020a1709073f9100b00a51c48bee20si3303507ejc.1015.2024.04.09.07.04.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 07:04:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137049-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=seYFDBBN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-137049-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137049-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 188101F21F67 for ; Tue, 9 Apr 2024 14:03:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8789131E5D; Tue, 9 Apr 2024 14:01:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="seYFDBBN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF3D41311B9; Tue, 9 Apr 2024 14:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671283; cv=none; b=UCM1Vd5/tKR/jkD3QxamFkrGDgf9RRQyk17NWint7ykWeBCCwRr0IZ4rfvsHOyVM8X+pAxZQuaydphuD9W27xY3z0XbQl9H3j2GLF32d7oOunOvIKw1nA2xgxzSTlAaytTqNTYRxMJ9KnYCWKsGrHoCxZzP0tMgRSP0Fpaeax3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671283; c=relaxed/simple; bh=+6XHH0IKbKZJZfLuR8UiLY5DybHOF/uJqvg3k5VIrYY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rd+fBWDsoEzUeYIgDJlqM1CRLCiazXSa6efWCLSO5Jofx0eR22avpH2ekLvuehnLfNiKziu02BL6lYqmAuvYnImN2nlV9aZvVAAyRiapLVn9iSSfowWAH3/82Y1bwZrergV1P9yV09SqAozTSswS7mmfUCp4SEd6SE0tKrxon9M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=seYFDBBN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB531C43601; Tue, 9 Apr 2024 14:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712671283; bh=+6XHH0IKbKZJZfLuR8UiLY5DybHOF/uJqvg3k5VIrYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=seYFDBBNQDwm3rbyua/v8J3aR2fdaXaheTfVVTdXR7eE7sMrmz3miSMjwS+ALRTjO 3keDS7/WA23UgDKScxs2qbPxAnxQq5cKW2mqPPIzRmx4q+oajuSJYMhsI8NPbxIyDe r8JSc6Wgt3n9s+H0fYI8xAqv0qbNj5HjUi/CceuFaOYrBzwSHYdlvQtFE7HpZT7Icf Jg9mP/RwmYcvzfeiTgsNl/sQ7NDJHRRJBuPTy7r8unNf7A3LnopNDxu/rlBnjOOKP+ U7BAgVieDFa+2RczYDaBt0X77ALDKlU+jKCIDGhyluyaj9mTJOimEu/sG7GQGhji7S y15jJwN/Osm5Q== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , "Richard Russon" , Jens Axboe , Robert Moore , "Rafael J. Wysocki" , Len Brown , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Lin Ming , Alexey Starikovskiy , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, linux-trace-kernel@vger.kernel.org, Justin Stitt Subject: [PATCH 3/5] [v2] block/partitions/ldm: convert strncpy() to strscpy() Date: Tue, 9 Apr 2024 16:00:56 +0200 Message-Id: <20240409140059.3806717-4-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240409140059.3806717-1-arnd@kernel.org> References: <20240409140059.3806717-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Arnd Bergmann The strncpy() here can cause a non-terminated string, which older gcc versions such as gcc-9 warn about: In function 'ldm_parse_tocblock', inlined from 'ldm_validate_tocblocks' at block/partitions/ldm.c:386:7, inlined from 'ldm_partition' at block/partitions/ldm.c:1457:7: block/partitions/ldm.c:134:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] 134 | strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ block/partitions/ldm.c:145:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] 145 | strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ New versions notice that the code is correct after all because of the following termination, but replacing the strncpy() with strscpy_pad() or strcpy() avoids the warning and simplifies the code at the same time. Use the padding version here to keep the existing behavior, in case the code relies on not including uninitialized data. Reviewed-by: Justin Stitt Signed-off-by: Arnd Bergmann --- block/partitions/ldm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c index 38e58960ae03..2bd42fedb907 100644 --- a/block/partitions/ldm.c +++ b/block/partitions/ldm.c @@ -131,8 +131,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc) ldm_crit ("Cannot find TOCBLOCK, database may be corrupt."); return false; } - strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name)); - toc->bitmap1_name[sizeof (toc->bitmap1_name) - 1] = 0; + strscpy_pad(toc->bitmap1_name, data + 0x24, sizeof(toc->bitmap1_name)); toc->bitmap1_start = get_unaligned_be64(data + 0x2E); toc->bitmap1_size = get_unaligned_be64(data + 0x36); @@ -142,8 +141,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc) TOC_BITMAP1, toc->bitmap1_name); return false; } - strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name)); - toc->bitmap2_name[sizeof (toc->bitmap2_name) - 1] = 0; + strscpy_pad(toc->bitmap2_name, data + 0x46, sizeof(toc->bitmap2_name)); toc->bitmap2_start = get_unaligned_be64(data + 0x50); toc->bitmap2_size = get_unaligned_be64(data + 0x58); if (strncmp (toc->bitmap2_name, TOC_BITMAP2, -- 2.39.2