From: Dan Carpenter <dan.carpenter@linaro.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Justin Stitt <justinstitt@google.com>,
Arnd Bergmann <arnd@arndb.de>,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] [v2] staging: rts5208: replace weird strncpy() with memcpy()
Date: Tue, 9 Apr 2024 09:23:45 +0300 [thread overview]
Message-ID: <bcef5496-31e7-4fe9-ae4b-b1e335eb099b@moroto.mountain> (raw)
In-Reply-To: <20240408194821.3183462-1-arnd@kernel.org>
On Mon, Apr 08, 2024 at 09:48:09PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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 88a5b39b69ab ("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>
> ---
> v2: remove unneeded space byte from input string for clarity,
> rework changelog text
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
regards,
dan carpenter
prev parent reply other threads:[~2024-04-09 6:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 19:48 Arnd Bergmann
2024-04-08 19:48 ` [PATCH 2/3] [v2] staging: rtl8723bs: convert strncpy to strscpy Arnd Bergmann
2024-04-08 20:35 ` Justin Stitt
2024-04-09 7:10 ` Dan Carpenter
2024-04-08 19:48 ` [PATCH 3/3] [v2] staging: greybus: change strncpy() to strscpy_pad() Arnd Bergmann
2024-04-08 20:38 ` Justin Stitt
2024-04-09 7:04 ` Dan Carpenter
2024-04-08 20:28 ` [PATCH 1/3] [v2] staging: rts5208: replace weird strncpy() with memcpy() Justin Stitt
2024-04-09 5:34 ` Arnd Bergmann
2024-04-09 6:23 ` Dan Carpenter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bcef5496-31e7-4fe9-ae4b-b1e335eb099b@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®