]> www.infradead.org Git - users/jedix/linux-maple.git/commit
Bluetooth: replace deprecated strncpy with strscpy_pad
authorJustin Stitt <justinstitt@google.com>
Thu, 5 Sep 2024 22:54:40 +0000 (15:54 -0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 10 Sep 2024 17:06:55 +0000 (13:06 -0400)
commita1f1c24368ec9b1d2bbc77075d2ba340ea9d0a83
tree975047f853913e5bca1831ec86800fff5bc1aea9
parentd47da6bd4cfa982fe903f33423b9e2ec541e9496
Bluetooth: replace deprecated strncpy with strscpy_pad

strncpy() is deprecated for use on NUL-terminated destination strings [0]
and as such we should prefer more robust and less ambiguous string interfaces.

The CAPI (part II) [1] states that the manufacturer id should be a
"zero-terminated ASCII string" and should "always [be] zero-terminated."

Much the same for the serial number: "The serial number, a seven-digit
number coded as a zero-terminated ASCII string".

Along with this, its clear the original author intended for these
buffers to be NUL-padded as well. To meet the specification as well as
properly NUL-pad, use strscpy_pad().

In doing this, an opportunity to simplify this code is also present.
Remove the min_t() and combine the length check into the main if.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://capi.org/downloads.html
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/cmtp/capi.c