PNP: ACPI: Fix string truncation warning
authorSunil V L <sunilvl@ventanamicro.com>
Tue, 25 Jul 2023 05:29:25 +0000 (10:59 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 17 Aug 2023 17:38:35 +0000 (19:38 +0200)
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 to be a valid issue since the destination string may not be
null-terminated.

To fix this, append the NUL explicitly after the strncpy().

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202307241942.Rff2Nri5-lkp@intel.com/
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/pnp/pnpacpi/core.c

index 38928ff..6ab272c 100644 (file)
@@ -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);