scsi_serial: replace some crazy strncpy() calls by strnlen()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 May 2019 13:58:29 +0000 (15:58 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 May 2019 19:06:44 +0000 (21:06 +0200)
commit099c77fd5ff835614dea8dc11c57f6d44f77d9ee
treedd59ab76c7dc0dc7c0d7d196f5209f2988a57b20
parent6695c200bd5f0cbe65647fcdafa2f1dbed4b6a64
scsi_serial: replace some crazy strncpy() calls by strnlen()

gcc was warning about strncpy() leaving an unterminated string.
In this case, it was correct.

The code was doing strncpy()+strncat()+strlen() essentially to determine
if the strings have expected length. If the length was correct, a buffer
overread was performed (or at least some garbage bytes were used from the
uninitialized part of the buffer). Let's do the length check first and then
only copy stuff if everything agrees.

For some reason the function was called "prepend", when it obviously does
an "append".
src/udev/scsi_id/scsi_serial.c