Skip to contentSkip to conversation

PNP/ACPI: Fix string truncation warning

PATCH Applied Sunil V L 2 participants 2 messages Jul 25, 2023 – Aug 17, 2023

Subsystems (2)
lore
Share & tools
lore

Sunil V L

author
#0 lore raw

PATCH 1/1 PNP/ACPI: Fix string truncation warning

LKP reports below warning when building for RISC-V.

drivers/pnp/pnpacpi/core.c:253:17:
warning: 'strncpy' specified bound 50 equals destination size [-Wstringop-truncation]

This appears like a valid issue since the destination string may not be null-terminated. To fix this, append the NUL explicitly after the strncpy.

---
 drivers/pnp/pnpacpi/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pnp/pnpacpi/core.c +3 -0
index 38928ff7472b..6ab272c84b7b 100644
@@ -254,6 +254,9 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
 	else
 		strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
 
+	/* Handle possible string truncation */
+	dev->name[sizeof(dev->name) - 1] = '\0';
+
 	if (dev->active)
 		pnpacpi_parse_allocated_resource(dev);
 
Signature · 1 line
2.39.2
maintainer Applied
#1 lore raw
Quoted 23 lines · Sunil V L

LKP reports below warning when building for RISC-V.

drivers/pnp/pnpacpi/core.c:253:17:
warning: 'strncpy' specified bound 50 equals destination size [-Wstringop-truncation]

This appears like a valid issue since the destination string may not be null-terminated. To fix this, append the NUL explicitly after the strncpy.

---
 drivers/pnp/pnpacpi/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pnp/pnpacpi/core.c +0 -0
index 38928ff7472b..6ab272c84b7b 100644

drivers/pnp/pnpacpi/core.c static int __init pnpacpi_add_device(struct acpi_device *device)

Quoted 10 lines
drivers/pnp/pnpacpi/core.c +3 -1
@@ -254,6 +254,9 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
        else
                strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
 
+       /* Handle possible string truncation */
+       dev->name[sizeof(dev->name) - 1] = '\0';
+
        if (dev->active)
                pnpacpi_parse_allocated_resource(dev);
 
--

Applied as 6.6 material, thanks!