From: Abhishek Tamboli <abhishektamboli9@gmail.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: gregkh@linuxfoundation.org, tdavies@darkphysics.net,
philipp.g.hortmann@gmail.com, garyrookard@fastmail.org,
linux-staging@lists.linux.dev, skhan@linuxfoundation.org,
rbmarliere@gmail.com,
linux-kernel-mentees@lists.linuxfoundation.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: rtl8192e: Replace strcpy with strscpy in rtl819x_translate_scan
Date: Wed, 21 Aug 2024 23:18:17 +0530 [thread overview]
Message-ID: <ZsYoYe+8k0YEyS2U@embed-PC.myguest.virtualbox.org> (raw)
In-Reply-To: <b2efc687-07bd-462a-b0a5-58e09bde32a7@stanley.mountain>
On Tue, Aug 20, 2024 at 10:29:47PM +0300, Dan Carpenter wrote:
> On Wed, Aug 21, 2024 at 12:12:16AM +0530, Abhishek Tamboli wrote:
> > Replace strcpy() with strscpy() in rtl819x_translate_scan()
> > function to ensure buffer safety.
> >
> > Signed-off-by: Abhishek Tamboli <abhishektamboli9@gmail.com>
> > ---
> > drivers/staging/rtl8192e/rtllib_wx.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
> > index fbd4ec824084..970b7fcb3f7e 100644
> > --- a/drivers/staging/rtl8192e/rtllib_wx.c
> > +++ b/drivers/staging/rtl8192e/rtllib_wx.c
> > @@ -61,7 +61,7 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> > iwe.cmd = SIOCGIWNAME;
> > for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {
> > if (network->mode & BIT(i)) {
> > - strcpy(pname, rtllib_modes[i]);
> > + strscpy(pname, rtllib_modes[i], sizeof(pname));
> ^^^^^
> pname is a pointer, not an array, so this doesn't work.
Thanks for pointing out the issue with strscpy.
> > pname += strlen(rtllib_modes[i]);
> ^^^^^^^^
> pname is incremented here.
>
> What this loop is doing is that it's going through all the network modes and
> adding to the string. You should look at the rtllib_modes[] array and ensure
> that if we printed every string it would fit into pname. (Currently that is not
> the case. Probably not all network modes are possible. But I have looked at
> this code and I'm saying that we should just ensure that we could handle it if
> they were all possible).
I understand that the size of proto_name is insufficient if all network modes
from rtllib_modes[] are copied, so I need to increase its size.
Given this, would it be better to use strcat?
This would eliminate the need for the pname pointer and align with
the current code's method of concatenating the rtllib_modes.
Regards,
Abhishek
next prev parent reply other threads:[~2024-08-21 17:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 18:42 [PATCH] staging: rtl8192e: Replace strcpy with strscpy in rtl819x_translate_scan Abhishek Tamboli
2024-08-20 19:29 ` Dan Carpenter
2024-08-21 17:48 ` Abhishek Tamboli [this message]
2024-08-21 18:22 ` Dan Carpenter
2024-08-20 19:38 ` Christophe JAILLET
2024-08-21 18:23 ` Dan Carpenter
2024-08-24 6:35 ` Christophe JAILLET
2024-08-24 11:18 ` Dan Carpenter
2024-08-21 9:43 ` kernel test robot
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=ZsYoYe+8k0YEyS2U@embed-PC.myguest.virtualbox.org \
--to=abhishektamboli9@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=garyrookard@fastmail.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=philipp.g.hortmann@gmail.com \
--cc=rbmarliere@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=tdavies@darkphysics.net \
/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