Skip to content

Commit f1fce1c

Browse files
JustinStittrafaeljw
authored andcommitted
ACPI: OSI: refactor deprecated strncpy()
`strncpy()` is deprecated for use on NUL-terminated destination strings [1]. We know `osi->string` is a NUL-terminated string due to its eventual use in `acpi_install_interface()` and `acpi_remove_interface()` which expect a `acpi_string` which has been specifically typedef'd as: | typedef char *acpi_string; /* Null terminated ASCII string */ ... and which also has other string functions used on it like `strlen`. Furthermore, padding is not needed in this instance either. Due to the reasoning above a suitable replacement is `strscpy` [2] since it guarantees NUL-termination on the destination buffer and doesn't unnecessarily NUL-pad. While there is unlikely to be a buffer overread (or other related bug) in this case, we should still favor a more robust and less ambiguous interface. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: KSPP#90 Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ce9ecca commit f1fce1c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/acpi/osi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void __init acpi_osi_setup(char *str)
110110
break;
111111
} else if (osi->string[0] == '\0') {
112112
osi->enable = enable;
113-
strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
113+
strscpy(osi->string, str, OSI_STRING_LENGTH_MAX);
114114
break;
115115
}
116116
}

0 commit comments

Comments
 (0)