* [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()
@ 2021-04-13 12:30 Fabio M. De Francesco
2021-04-13 12:59 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Fabio M. De Francesco @ 2021-04-13 12:30 UTC (permalink / raw)
To: outreachy-kernel, Greg Kroah-Hartman, linux-staging, linux-kernel
Cc: Fabio M. De Francesco
Replaced strncpy() with strscpy() because of compilation time warnings
about possible truncation of output [-Wstringop-truncation].
Furthermore, according to the Linux official documentation, strscpy() is
preferred to strncpy.
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index 25ea8e1b6b65..aa58eedf5e86 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -1385,12 +1385,12 @@ inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee
* essid provided by the user.
*/
if (!ssidbroad) {
- strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
+ strscpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
tmp_ssid_len = ieee->current_network.ssid_len;
}
memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
- strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
+ strscpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
ieee->current_network.ssid_len = tmp_ssid_len;
netdev_info(ieee->dev,
"Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d\n",
--
2.31.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()
2021-04-13 12:30 [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy() Fabio M. De Francesco
@ 2021-04-13 12:59 ` Greg Kroah-Hartman
2021-04-13 13:12 ` Fabio M. De Francesco
0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-04-13 12:59 UTC (permalink / raw)
To: Fabio M. De Francesco; +Cc: outreachy-kernel, linux-staging, linux-kernel
On Tue, Apr 13, 2021 at 02:30:41PM +0200, Fabio M. De Francesco wrote:
> Replaced strncpy() with strscpy() because of compilation time warnings
> about possible truncation of output [-Wstringop-truncation].
build warnings? What build warnings?
> Furthermore, according to the Linux official documentation, strscpy() is
> preferred to strncpy.
>
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
> drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> index 25ea8e1b6b65..aa58eedf5e86 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> @@ -1385,12 +1385,12 @@ inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee
> * essid provided by the user.
> */
> if (!ssidbroad) {
> - strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
> + strscpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
Are you sure you can just replace this like this?
> tmp_ssid_len = ieee->current_network.ssid_len;
> }
> memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
>
> - strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
> + strscpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
Same here, are you sure?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()
2021-04-13 12:59 ` Greg Kroah-Hartman
@ 2021-04-13 13:12 ` Fabio M. De Francesco
2021-04-13 13:16 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Fabio M. De Francesco @ 2021-04-13 13:12 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: outreachy-kernel, linux-staging, linux-kernel
On Tuesday, April 13, 2021 2:59:29 PM CEST Greg Kroah-Hartman wrote:
> On Tue, Apr 13, 2021 at 02:30:41PM +0200, Fabio M. De Francesco wrote:
> > Replaced strncpy() with strscpy() because of compilation time warnings
> > about possible truncation of output [-Wstringop-truncation].
>
> build warnings? What build warnings?
>
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:1388:5: warning:
‘strncpy’ output may be truncated copying 32 bytes from a string of length
32 [-Wstringop-truncation]
1388 | strncpy(tmp_ssid, ieee->current_network.ssid,
IW_ESSID_MAX_SIZE);
>
> > Furthermore, according to the Linux official documentation, strscpy()
> > is
> > preferred to strncpy.
> >
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >
> > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index
> > 25ea8e1b6b65..aa58eedf5e86 100644
> > --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > @@ -1385,12 +1385,12 @@ inline void ieee80211_softmac_new_net(struct
> > ieee80211_device *ieee, struct ieee>
> > * essid provided by the user.
> > */
> >
> > if (!ssidbroad) {
> >
> > - strncpy(tmp_ssid, ieee-
>current_network.ssid, IW_ESSID_MAX_SIZE);
> > + strscpy(tmp_ssid, ieee-
>current_network.ssid, IW_ESSID_MAX_SIZE);
>
> Are you sure you can just replace this like this?
>
I surely was... but now I'm not anymore, since your review :)
Maybe you mean I have to check possible return of -E2BIG?
Did you mean something else?
May you please elaborate further?
Thanks,
Fabio
>
> > tmp_ssid_len = ieee-
>current_network.ssid_len;
> >
> > }
> > memcpy(&ieee->current_network, net,
sizeof(struct
> > ieee80211_network));
> >
> > - strncpy(ieee->current_network.ssid,
tmp_ssid, IW_ESSID_MAX_SIZE);
> > + strscpy(ieee->current_network.ssid,
tmp_ssid, IW_ESSID_MAX_SIZE);
>
> Same here, are you sure?
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()
2021-04-13 13:12 ` Fabio M. De Francesco
@ 2021-04-13 13:16 ` Greg Kroah-Hartman
2021-04-13 13:24 ` Fabio M. De Francesco
0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-04-13 13:16 UTC (permalink / raw)
To: Fabio M. De Francesco; +Cc: outreachy-kernel, linux-staging, linux-kernel
On Tue, Apr 13, 2021 at 03:12:02PM +0200, Fabio M. De Francesco wrote:
> On Tuesday, April 13, 2021 2:59:29 PM CEST Greg Kroah-Hartman wrote:
> > On Tue, Apr 13, 2021 at 02:30:41PM +0200, Fabio M. De Francesco wrote:
> > > Replaced strncpy() with strscpy() because of compilation time warnings
> > > about possible truncation of output [-Wstringop-truncation].
> >
> > build warnings? What build warnings?
> >
> drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:1388:5: warning:
> ‘strncpy’ output may be truncated copying 32 bytes from a string of length
> 32 [-Wstringop-truncation]
> 1388 | strncpy(tmp_ssid, ieee->current_network.ssid,
> IW_ESSID_MAX_SIZE);
That's implying that there is a real bug here, not that just replacing
it with a different call is going to solve this, right?
And how do you see that, I can't see that in my builds.
> >
> > > Furthermore, according to the Linux official documentation, strscpy()
> > > is
> > > preferred to strncpy.
> > >
> > > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > > ---
> > >
> > > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > > b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index
> > > 25ea8e1b6b65..aa58eedf5e86 100644
> > > --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > > +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > > @@ -1385,12 +1385,12 @@ inline void ieee80211_softmac_new_net(struct
> > > ieee80211_device *ieee, struct ieee>
> > > * essid provided by the user.
> > > */
> > >
> > > if (!ssidbroad) {
> > >
> > > - strncpy(tmp_ssid, ieee-
> >current_network.ssid, IW_ESSID_MAX_SIZE);
> > > + strscpy(tmp_ssid, ieee-
> >current_network.ssid, IW_ESSID_MAX_SIZE);
> >
> > Are you sure you can just replace this like this?
> >
> I surely was... but now I'm not anymore, since your review :)
>
> Maybe you mean I have to check possible return of -E2BIG?
> Did you mean something else?
> May you please elaborate further?
If it was as simple as search/replace, we would have already done that
on the whole codebase at once. It's not that simple :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()
2021-04-13 13:16 ` Greg Kroah-Hartman
@ 2021-04-13 13:24 ` Fabio M. De Francesco
2021-04-13 15:04 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Fabio M. De Francesco @ 2021-04-13 13:24 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: outreachy-kernel, linux-staging, linux-kernel
On Tuesday, April 13, 2021 3:16:17 PM CEST Greg Kroah-Hartman wrote:
> On Tue, Apr 13, 2021 at 03:12:02PM +0200, Fabio M. De Francesco wrote:
> > On Tuesday, April 13, 2021 2:59:29 PM CEST Greg Kroah-Hartman wrote:
> > > On Tue, Apr 13, 2021 at 02:30:41PM +0200, Fabio M. De Francesco
wrote:
> > > > Replaced strncpy() with strscpy() because of compilation time
> > > > warnings
> > > > about possible truncation of output [-Wstringop-truncation].
> > >
> > > build warnings? What build warnings?
> >
> > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:1388:5: warning:
> > ‘strncpy’ output may be truncated copying 32 bytes from a string of
> > length 32 [-Wstringop-truncation]
> >
> > 1388 | strncpy(tmp_ssid, ieee->current_network.ssid,
> >
> > IW_ESSID_MAX_SIZE);
>
> That's implying that there is a real bug here, not that just replacing
> it with a different call is going to solve this, right?
>
> And how do you see that, I can't see that in my builds.
>
I see that with flag W=1 like in
make -j8 drivers/staging/rtl8192u/ W=1
However I also think it's not a real issue in this context.
Just that strscpy() is preferred and get rid of warnings.
You only can judge if a patch is worth.
I just thought that gcc is (mostly) right in pointing out warnings like
that.
Thanks,
Fabio
>
> > > > Furthermore, according to the Linux official documentation,
> > > > strscpy()
> > > > is
> > > > preferred to strncpy.
> > > >
> > > > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > > > ---
> > > >
> > > > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
> > > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > > > b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index
> > > > 25ea8e1b6b65..aa58eedf5e86 100644
> > > > --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > > > +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > > > @@ -1385,12 +1385,12 @@ inline void
> > > > ieee80211_softmac_new_net(struct
> > > > ieee80211_device *ieee, struct ieee>
> > > >
> > > > * essid provided by the user.
> > > > */
> > > >
> > > > if (!ssidbroad) {
> > > >
> > > > - strncpy(tmp_ssid, ieee-
> > >
> > >current_network.ssid, IW_ESSID_MAX_SIZE);
> > >
> > > > + strscpy(tmp_ssid, ieee-
> > >
> > >current_network.ssid, IW_ESSID_MAX_SIZE);
> > >
> > > Are you sure you can just replace this like this?
> >
> > I surely was... but now I'm not anymore, since your review :)
> >
> > Maybe you mean I have to check possible return of -E2BIG?
> > Did you mean something else?
> > May you please elaborate further?
>
> If it was as simple as search/replace, we would have already done that
> on the whole codebase at once. It's not that simple :)
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()
2021-04-13 13:24 ` Fabio M. De Francesco
@ 2021-04-13 15:04 ` Greg Kroah-Hartman
0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-04-13 15:04 UTC (permalink / raw)
To: Fabio M. De Francesco; +Cc: outreachy-kernel, linux-staging, linux-kernel
On Tue, Apr 13, 2021 at 03:24:31PM +0200, Fabio M. De Francesco wrote:
> On Tuesday, April 13, 2021 3:16:17 PM CEST Greg Kroah-Hartman wrote:
> > On Tue, Apr 13, 2021 at 03:12:02PM +0200, Fabio M. De Francesco wrote:
> > > On Tuesday, April 13, 2021 2:59:29 PM CEST Greg Kroah-Hartman wrote:
> > > > On Tue, Apr 13, 2021 at 02:30:41PM +0200, Fabio M. De Francesco
> wrote:
> > > > > Replaced strncpy() with strscpy() because of compilation time
> > > > > warnings
> > > > > about possible truncation of output [-Wstringop-truncation].
> > > >
> > > > build warnings? What build warnings?
> > >
> > > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:1388:5: warning:
> > > ‘strncpy’ output may be truncated copying 32 bytes from a string of
> > > length 32 [-Wstringop-truncation]
> > >
> > > 1388 | strncpy(tmp_ssid, ieee->current_network.ssid,
> > >
> > > IW_ESSID_MAX_SIZE);
> >
> > That's implying that there is a real bug here, not that just replacing
> > it with a different call is going to solve this, right?
> >
> > And how do you see that, I can't see that in my builds.
> >
> I see that with flag W=1 like in
> make -j8 drivers/staging/rtl8192u/ W=1
Ah, no one "normal" builds with "W=1" :)
> However I also think it's not a real issue in this context.
> Just that strscpy() is preferred and get rid of warnings.
> You only can judge if a patch is worth.
> I just thought that gcc is (mostly) right in pointing out warnings like
> that.
Check and verify if this is wrong as-is and if so, then replace it
properly. Don't just blindly to a search/replace, as that's not ok
here.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-04-13 15:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 12:30 [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy() Fabio M. De Francesco
2021-04-13 12:59 ` Greg Kroah-Hartman
2021-04-13 13:12 ` Fabio M. De Francesco
2021-04-13 13:16 ` Greg Kroah-Hartman
2021-04-13 13:24 ` Fabio M. De Francesco
2021-04-13 15:04 ` Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.