]> git.baikalelectronics.ru Git - kernel.git/commit
Revert "HID: uhid: use strlcpy() instead of strncpy()"
authorDavid Herrmann <dh.herrmann@gmail.com>
Wed, 14 Nov 2018 13:16:42 +0000 (14:16 +0100)
committerJiri Kosina <jkosina@suse.cz>
Mon, 19 Nov 2018 13:32:27 +0000 (14:32 +0100)
commit6ce17a0e81dcdedf9fc1b558985ecd5a537e0535
treef1a9ff9487e6984b11310d08d43f37c207ee7b66
parent92e1adac4b7461a0782b73f3b267521f5cda7edf
Revert "HID: uhid: use strlcpy() instead of strncpy()"

This reverts commit 07475d07f353ff8eb49927bd3e3cead9baca7401.

Please note that `strlcpy()` does *NOT* do what you think it does.
strlcpy() *ALWAYS* reads the full input string, regardless of the
'length' parameter. That is, if the input is not zero-terminated,
strlcpy() will *READ* beyond input boundaries. It does this, because it
always returns the size it *would* copy if the target was big enough,
not the truncated size it actually copied.

The original code was perfectly fine. The hid device is
zero-initialized and the strncpy() functions copied up to n-1
characters. The result is always zero-terminated this way.

This is the third time someone tried to replace strncpy with strlcpy in
this function, and gets it wrong. I now added a comment that should at
least make people reconsider.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/uhid.c