Skip to content

Commit f2ac14b

Browse files
Wer-Wolfrafaeljw
authored andcommitted
ACPI: battery: Fix missing NUL-termination with large strings
When encountering a string bigger than the destination buffer (32 bytes), the string is not properly NUL-terminated, causing buffer overreads later. This for example happens on the Inspiron 3505, where the battery model name is larger than 32 bytes, which leads to sysfs showing the model name together with the serial number string (which is NUL-terminated and thus prevents worse). Fix this by using strscpy() which ensures that the result is always NUL-terminated. Fixes: 106449e ("ACPI: Battery: Allow extract string from integer") Signed-off-by: Armin Wolf <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 5dc4c99 commit f2ac14b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/acpi/battery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static int extract_package(struct acpi_battery *battery,
440440

441441
if (element->type == ACPI_TYPE_STRING ||
442442
element->type == ACPI_TYPE_BUFFER)
443-
strncpy(ptr, element->string.pointer, 32);
443+
strscpy(ptr, element->string.pointer, 32);
444444
else if (element->type == ACPI_TYPE_INTEGER) {
445445
strncpy(ptr, (u8 *)&element->integer.value,
446446
sizeof(u64));

0 commit comments

Comments
 (0)