From: Ahmed Salem <x0rw3ll@gmail.com>
To: robert.moore@intel.com, rafael.j.wysocki@intel.com, lenb@kernel.org
Cc: skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linuxfoundation.org,
linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/2] ACPI: replace deprecated strncpy() with strtomem()
Date: Sun, 30 Mar 2025 07:55:18 +0200 [thread overview]
Message-ID: <6c1a263a89712b5cdc2a6752a91bb9f71f379a2a.1743313252.git.x0rw3ll@gmail.com> (raw)
In-Reply-To: <cover.1743313252.git.x0rw3ll@gmail.com>
strncpy() is deprecated for NUL-terminated destination buffers[1].
Use strtomem() for ACPI_COPY_NAMESEG() as destinations are length-bounded,
and not all of them require NUL termination.
Also replace strncpy() with memcpy() for copying header.oem_id
and header.oem_table_id
[1] https://github.com/KSPP/linux/issues/90
Signed-off-by: Ahmed Salem <x0rw3ll@gmail.com>
---
drivers/acpi/acpica/tbfind.c | 4 ++--
include/acpi/actypes.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/acpica/tbfind.c b/drivers/acpi/acpica/tbfind.c
index 1c1b2e284bd9..35f72dffc250 100644
--- a/drivers/acpi/acpica/tbfind.c
+++ b/drivers/acpi/acpica/tbfind.c
@@ -57,8 +57,8 @@ acpi_tb_find_table(char *signature,
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);
+ memcpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
+ memcpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
/* Search for the table */
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index 80767e8bf3ad..b85dec57f00d 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -522,7 +522,7 @@ typedef u64 acpi_integer;
#define ACPI_COPY_NAMESEG(dest,src) (*ACPI_CAST_PTR (u32, (dest)) = *ACPI_CAST_PTR (u32, (src)))
#else
#define ACPI_COMPARE_NAMESEG(a,b) (!strncmp (ACPI_CAST_PTR (char, (a)), ACPI_CAST_PTR (char, (b)), ACPI_NAMESEG_SIZE))
-#define ACPI_COPY_NAMESEG(dest,src) (strncpy (ACPI_CAST_PTR (char, (dest)), ACPI_CAST_PTR (char, (src)), ACPI_NAMESEG_SIZE))
+#define ACPI_COPY_NAMESEG(dest, src) (strtomem (ACPI_CAST_PTR (char, (dest)), ACPI_CAST_PTR (char, (src))))
#endif
/* Support for the special RSDP signature (8 characters) */
--
2.47.2
prev parent reply other threads:[~2025-03-30 5:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-30 5:53 [RFC PATCH 0/2] ACPI: replace deprecated strncpy() Ahmed Salem
2025-03-30 5:54 ` [RFC PATCH 1/2] ACPI: mark ACPI_COPY_NAMESEG destinations with __nonstring attribute Ahmed Salem
2025-03-31 11:49 ` Rafael J. Wysocki
2025-03-31 17:55 ` Ahmed Salem
2025-03-30 5:55 ` Ahmed Salem [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c1a263a89712b5cdc2a6752a91bb9f71f379a2a.1743313252.git.x0rw3ll@gmail.com \
--to=x0rw3ll@gmail.com \
--cc=acpica-devel@lists.linux.dev \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=robert.moore@intel.com \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox