Skip to contentSkip to conversation

ACPICA: Switch back to using strncpy() in acpi_ut_safe_strncpy()

PATCH New Rafael J. Wysocki 1 participant 1 message May 29, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPICA: Switch back to using strncpy() in acpi_ut_safe_strncpy()

From: Ahmed Salem <[email protected]>

ACPICA commit b90d0d65ec97ff8279ad826f4102e0d31c5f662a

I mistakenly replaced strncpy() with memcpy() in commit ebf27765421c ("ACPICA: Replace strncpy() with memcpy()"), not realizing the entire context behind *why* strncpy() was used.

In this safer implementation of strncpy(), it does not make sense to use memcpy() only to null-terminate strings passed to acpi_ut_safe_strncpy() one byte early.

The consequences of doing so are understandably *bad*, as was evident by the kernel test bot reporting problems [1].

---
 utnonansi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/utnonansi.c +1 -1
diff -Nurp linux.before_name/drivers/acpi/acpica/utnonansi.c linux.after_name/drivers/acpi/acpica/utnonansi.c
@@ -168,7 +168,7 @@ void acpi_ut_safe_strncpy(char *dest, ch
 {
 	/* Always terminate destination string */
 
-	memcpy(dest, source, dest_size);
+	strncpy(dest, source, dest_size);
 	dest[dest_size - 1] = 0;
 }