ACPI: battery: Fix buffer overread if not NUL-terminated
authorArmin Wolf <W_Armin@gmx.de>
Thu, 19 Jan 2023 14:21:14 +0000 (15:21 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 30 Jan 2023 15:43:25 +0000 (16:43 +0100)
commita1a32ded2887fd421d67e9c9b67ae4504bdb08c9
treee0e87ed8a9e2e803221a2faf35433aaccf9390bb
parentf2ac14b5f197e4a2dec51e5ceaa56682ff1592bc
ACPI: battery: Fix buffer overread if not NUL-terminated

If a buffer containing ASCII characters is not NUL-terminated
(which is perfectly legal according to the ACPI specification),
the ACPI battery driver might not honor its length.
Fix this by limiting the amount of data to be copied to
the buffer length while also using strscpy() to make sure
that the resulting string is always NUL-terminated.
Also replace strncpy() vs strscpy().

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/battery.c