Skip to contentSkip to conversation

ACPI: event: replace strcpy() by strscpy()

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages Apr 22, 2019 – May 1, 2019 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: event: replace strcpy() by strscpy()

The strcpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warnings:

"You might overrun the 15-character fixed-size string event->bus_id by copying bus_id without checking the length."

"You might overrun the 20-character fixed-size string event->device_class by copying device_class without checking the length."

Addresses-Coverity-ID: 139001 ("Copy into fixed size buffer")

---
 drivers/acpi/event.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/event.c +2 -2
index 5a127f3f2d5c..47f21599f2ab 100644
@@ -131,8 +131,8 @@ int acpi_bus_generate_netlink_event(const char *device_class,
 	event = nla_data(attr);
 	memset(event, 0, sizeof(struct acpi_genl_event));
 
-	strcpy(event->device_class, device_class);
-	strcpy(event->bus_id, bus_id);
+	strscpy(event->device_class, device_class, sizeof(event->device_class));
+	strscpy(event->bus_id, bus_id, sizeof(event->bus_id));
 	event->type = type;
 	event->data = data;
 
Signature · 1 line
2.21.0
#1 lore raw
Quoted 21 lines · CEST Gustavo A. R. Silva

The strcpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warnings:

"You might overrun the 15-character fixed-size string event->bus_id by copying bus_id without checking the length."

"You might overrun the 20-character fixed-size string event->device_class by copying device_class without checking the length."

Addresses-Coverity-ID: 139001 ("Copy into fixed size buffer")

---
 drivers/acpi/event.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/event.c +0 -0
index 5a127f3f2d5c..47f21599f2ab 100644

drivers/acpi/event.c int acpi_bus_generate_netlink_event(const char *device_class, · line 138

Quoted 10 lines
drivers/acpi/event.c +2 -2
@@ -131,8 +131,8 @@ int acpi_bus_generate_netlink_event(const char *device_class,
 	event = nla_data(attr);
 	memset(event, 0, sizeof(struct acpi_genl_event));
 
-	strcpy(event->device_class, device_class);
-	strcpy(event->bus_id, bus_id);
+	strscpy(event->device_class, device_class, sizeof(event->device_class));
+	strscpy(event->bus_id, bus_id, sizeof(event->bus_id));
 	event->type = type;
 	event->data = data;
 

Applied, thanks!