hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()
PATCH 1/1 hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()
Use strscpy() instead of strcpy() to prevent potential buffer overflows in acpi_device_name() and acpi_device_class(), which point to fixed-size buffers.
This change improves safety and aligns with current kernel cleanup efforts.
--- drivers/hwmon/acpi_power_meter.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/hwmon/acpi_power_meter.c +6 -2
@@ -890,8 +890,12 @@ static int acpi_power_meter_add(struct acpi_device *device) resource->sensors_valid =0 ; resource->acpi_dev = device;mutex_init (&resource->lock); -strcpy (acpi_device_name (device),ACPI_POWER_METER_DEVICE_NAME ); -strcpy (acpi_device_class (device),ACPI_POWER_METER_CLASS ); +strscpy (acpi_device_name (device), +ACPI_POWER_METER_DEVICE_NAME , +MAX_ACPI_DEVICE_NAME_LEN ); +strscpy (acpi_device_class (device), +ACPI_POWER_METER_CLASS , +MAX_ACPI_CLASS_NAME_LEN ); device->driver_data = resource;#if IS_REACHABLE (CONFIG_ACPI_IPMI )
Signature · 1 line
2.47.0
Guenter Roeck
maintainerQuoted 5 lines · Yacov Simhony
Use
strscpy()instead ofstrcpy()to prevent potential buffer overflows inacpi_device_name()andacpi_device_class(), which point to fixed-size buffers.This change improves safety and aligns with current kernel cleanup efforts.
ACPI_POWER_METER_DEVICE_NAME and ACPI_POWER_METER_CLASS are constant strings. There is no danger of buffer overflows. There is no safety improvement.
We should concentrate on fixing real problems, not imaginary ones.
Guenter