linux/drivers/staging/rts5208
Arnd Bergmann 1b61680cfe staging: rts5208: replace weird strncpy() with memcpy()
When -Wstringop-truncation is enabled, gcc finds a function that
always does a short copy:

In function 'inquiry',
    inlined from 'rtsx_scsi_handler' at drivers/staging/rts5208/rtsx_scsi.c:3210:12:
drivers/staging/rts5208/rtsx_scsi.c:526:17: error: 'strncpy' output truncated copying between 1 and 28 bytes from a string of length 28 [-Werror=stringop-truncation]
  526 |                 strncpy(buf + 8, inquiry_string, sendbytes - 8);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The code originally had a memcpy() that would overread the source string,
and commit 88a5b39b69 ("staging/rts5208: Fix read overflow in memcpy")
fixed this but introduced the warning about truncation in the process.

As Dan points out, the final space in the inquiry_string always gets
cut off, so remove it here for clarity, leaving exactly the 28 non-NUL
characters that can get copied into the output. In the 'pro_formatter_flag'
this is followed by another 20 bytes from the 'formatter_inquiry_str'
array, but there the output never contains a NUL-termination, and the
length is known, so memcpy() is the more logical choice.

Cc: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/lkml/695be581-548f-4e5e-a211-5f3b95568e77@moroto.mountain/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240408194821.3183462-1-arnd@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-09 17:53:50 +02:00
..
general.c
general.h
Kconfig
Makefile
ms.c staging: rts5208: Added value check 2023-01-17 19:18:41 +01:00
ms.h
rtsx_card.c
rtsx_card.h
rtsx_chip.c
rtsx_chip.h
rtsx_scsi.c staging: rts5208: replace weird strncpy() with memcpy() 2024-04-09 17:53:50 +02:00
rtsx_scsi.h
rtsx_sys.h
rtsx_transport.c staging: rts5208: Convert kmap() to kmap_local_page() 2022-04-04 07:33:47 +02:00
rtsx_transport.h
rtsx.c staging: rts5208: Remove macros scsi_lock(), scsi_unlock() 2023-10-15 18:20:35 +02:00
rtsx.h staging: rts5208: Remove macros scsi_lock(), scsi_unlock() 2023-10-15 18:20:35 +02:00
sd.c staging: rts5208: Correct line ending with '(' 2023-07-27 10:00:19 +02:00
sd.h
spi.c staging: rts5208: spi.c: fix codestyle error in dynamic debug code 2022-06-06 07:53:49 +02:00
spi.h
TODO
xd.c staging: rts5208: remove unused xd_check_err_code function 2023-03-22 10:18:27 +01:00
xd.h