Skip to contentSkip to conversation

tools/power/acpi: Replace unsafe strcpy with snprintf in apdump.c

PATCH New Sumeet Pawnikar 1 participant 1 message Feb 1

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

PATCH 1/1 tools/power/acpi: Replace unsafe strcpy with snprintf in apdump.c

Replace unsafe strcpy() calls with snprintf() in apdump.c to prevent potential buffer overflow vulnerabilities when handling table signatures. The snprintf() function performs automatic bounds checking to ensure the destination buffer is not overflowed.

No functional change.

---
 tools/power/acpi/tools/acpidump/apdump.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/power/acpi/tools/acpidump/apdump.c +5 -3
index 7a6223aa703c..b566f9b832f1 100644
@@ -308,15 +308,17 @@ int ap_dump_table_by_name(char *signature)
 
 	/* Table signatures are expected to be uppercase */
 
-	strcpy(local_signature, signature);
+	snprintf(local_signature, sizeof(local_signature), "%s", signature);
 	acpi_ut_strupr(local_signature);
 
 	/* To be friendly, handle tables whose signatures do not match the name */
 
 	if (ACPI_COMPARE_NAMESEG(local_signature, "FADT")) {
-		strcpy(local_signature, ACPI_SIG_FADT);
+		snprintf(local_signature, sizeof(local_signature), "%s",
+			 ACPI_SIG_FADT);
 	} else if (ACPI_COMPARE_NAMESEG(local_signature, "MADT")) {
-		strcpy(local_signature, ACPI_SIG_MADT);
+		snprintf(local_signature, sizeof(local_signature), "%s",
+			 ACPI_SIG_MADT);
 	}
 
 	/* Dump all instances of this signature (to handle multiple SSDTs) */
Signature · 1 line
2.43.0