Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp457398lqh; Thu, 28 Mar 2024 07:07:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYDtLXK7NVoHq5kglsubFMrGUHgWzRpg/9+0jvxIrTMC5TS3T3PFFQoJRBuk0Su/K7IbqsYxiTgDwy98bcuCjcVZG4yXaLpGmelf/QLw== X-Google-Smtp-Source: AGHT+IEBZuqC6G1g531VxEK08XAZLfjpSIZK23l4yYNH58QoA6CMuOhfhqNdzo9ko8YFljpbDAJv X-Received: by 2002:a6b:6905:0:b0:7d0:4747:2811 with SMTP id e5-20020a6b6905000000b007d047472811mr1827669ioc.7.1711634846145; Thu, 28 Mar 2024 07:07:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711634846; cv=pass; d=google.com; s=arc-20160816; b=lIUsYMkf0mhfimadjv60B8d4sZtJqUlbOGdsZgX/dzHEN9TyJfclmZdv9bhyNtPLvD q0sQe2+nTa4C8lQxVfLPuu6G8RPQOA/hF9WADIgqqbGvwi6DGDuqhsqH9iDOjR8bwLKc mg+vRCQFqPM/ntAMg6ADFo5edA5s2AOf5MNgjCjX4IBfs7S+FnNn3d4toDediJ3gcUe8 11xtNSDJELifnpEYK59tPCHlcyrL4hn1FsZILllHiHm6XoaXjY6eOl3BXfDllfxY6iv6 4YgUDJsPOr715Dhu2wHGgRSBYFMXHFvdmQZ+L8GqZ9Fzdkp1yOwkeQbBelBokUR8SHzE N/EQ== 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=RrTfv3V86OVSWR+kq6+mTBTDBHjw55JbWBUI+uc3T/c=; fh=T9q16PvU29NOZ91hVGu6SXetfsK18pigIt9ZomFSYts=; b=RLJGX6o621zPzqWIRr4NdpPi9eq6bISN5NN4og0hwx1sundTSRthZOoeIAHWCUlr/o iJ8DAQTm/NpjC7+zQ+s1IR1wLkcX7ktEzhjamHq6mppMPZDKtOs7RrEKT89BqeYrAjzY eBZuJshleNnSHBbY8iwbpHKTU4eakLIMVTlPJ5us0Y4uPewpH1rce5AGU3TNjNahcrA3 yH25poD5WkX5Zhj/HVW301SIiG/6xkieG4dr4CFbVBNOVwfV7bXuOwxCtDgv4dsqWgAr 37sHq/TKjhDcqxpxxmplOxULIMnygFw5ZquQ2o73sKX9+lZVqMTLGNgc+Yw+LhwKuX9T /l5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=btfiU8CF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123021-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123021-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s12-20020a02c50c000000b0047eb24fdb83si576353jam.68.2024.03.28.07.07.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 07:07:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123021-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=btfiU8CF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123021-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123021-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9A75729A032 for ; Thu, 28 Mar 2024 14:07:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D90A8288C; Thu, 28 Mar 2024 14:06:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="btfiU8CF" 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 80BB144C67; Thu, 28 Mar 2024 14:06:42 +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=1711634802; cv=none; b=iuqU66yZziqBqZaBasle+gitOlFquTCJa4K/osWIRCNtEv1WEt8rzedFy9IIE9BSd+Ch3SFFDe0N7q4rHRFSA45o6ih3RfVVX9+NNZe5liAX0RGAoVHMXLf+CTankTm9i4ZobwhwTQlIJ9yxzl3t0bNnm2N0cd7vBM+dUS4+KmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711634802; c=relaxed/simple; bh=lezpFM2DFivksVBQ+jcGXE6ARZQR+zJugCRJ8LauAOg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ctiy9Iy530Gmzxzvd/8dGkKT3zv2Gyte7QOrIMGIbNZ/CljMyS7TQ7KLy3k4avNl06uoL02Tp6dhFQFaBgraIDgt4hUay2HfY5nrctnegf03FYeAbvSBQLJ23CIC3emwG632VJNg7PNh7YE2PX6ucAsy+8JlocQTMtL7Dq241zo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=btfiU8CF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD52BC433C7; Thu, 28 Mar 2024 14:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711634802; bh=lezpFM2DFivksVBQ+jcGXE6ARZQR+zJugCRJ8LauAOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=btfiU8CFi3ZJpE6YEYkrNSnkajZh5p/OPkCeQtqKmhP61Z3AbzPlRLr1vqjRGWgUv 4NYQxyuOXQf/UOtzHaXO+vVcXaQd9eI57v/nK4ubYyfaUR2zYLM1QftIWpy+XGNRNH swbYRDzNe3lyoL8ahTFBq+VT18N3dRNB02b+LE0+li5tYVSiO/GWzL8UjqlQsNADle oRarDv9hUrzmtQkCNacsLuTQZ5EfKu7MGIeak/pjJw/L+OWFjGMnrYvOjMn8/V8X9K jemp4ib7rMMWMLjcgQ3sci6hfss19XYHNtQDyIFwaX/u56L+Ih+NWY9xDpx/C1m6B2 6CY0kLzc2Fa3A== From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Robert Moore , "Rafael J. Wysocki" , Alexey Starikovskiy , Lin Ming , Len Brown Cc: Arnd Bergmann , Len Brown , linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev Subject: [PATCH 06/11] acpi: avoid warning for truncated string copy Date: Thu, 28 Mar 2024 15:04:50 +0100 Message-Id: <20240328140512.4148825-7-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240328140512.4148825-1-arnd@kernel.org> References: <20240328140512.4148825-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 gcc -Wstringop-truncation warns about copying a string that results in a missing nul termination: drivers/acpi/acpica/tbfind.c: In function 'acpi_tb_find_table': drivers/acpi/acpica/tbfind.c:60:9: error: 'strncpy' specified bound 6 equals destination size [-Werror=stringop-truncation] 60 | strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/acpi/acpica/tbfind.c:61:9: error: 'strncpy' specified bound 8 equals destination size [-Werror=stringop-truncation] 61 | strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This one is intentional, so rewrite the code in a way that avoids the warning. Since there is already an extra strlen() and an overflow check, the actual size to be copied is already known here. Fixes: 47c08729bf1c ("ACPICA: Fix for LoadTable operator, input strings") Signed-off-by: Arnd Bergmann --- drivers/acpi/acpica/tbfind.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/acpica/tbfind.c b/drivers/acpi/acpica/tbfind.c index 1c1b2e284bd9..472ce2a6624b 100644 --- a/drivers/acpi/acpica/tbfind.c +++ b/drivers/acpi/acpica/tbfind.c @@ -36,7 +36,7 @@ acpi_tb_find_table(char *signature, { acpi_status status = AE_OK; struct acpi_table_header header; - u32 i; + u32 len, i; ACPI_FUNCTION_TRACE(tb_find_table); @@ -46,19 +46,18 @@ acpi_tb_find_table(char *signature, return_ACPI_STATUS(AE_BAD_SIGNATURE); } - /* Don't allow the OEM strings to be too long */ - - if ((strlen(oem_id) > ACPI_OEM_ID_SIZE) || - (strlen(oem_table_id) > ACPI_OEM_TABLE_ID_SIZE)) { - return_ACPI_STATUS(AE_AML_STRING_LIMIT); - } - /* Normalize the input strings */ memset(&header, 0, sizeof(struct acpi_table_header)); ACPI_COPY_NAMESEG(header.signature, signature); - strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE); - strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE); + len = strlen(oem_id); + if (len > ACPI_OEM_ID_SIZE) + return_ACPI_STATUS(AE_AML_STRING_LIMIT); + memcpy(header.oem_id, oem_id, len); + len = strlen(oem_table_id); + if (len > ACPI_OEM_TABLE_ID_SIZE) + return_ACPI_STATUS(AE_AML_STRING_LIMIT); + memcpy(header.oem_table_id, oem_table_id, len); /* Search for the table */ -- 2.39.2