Skip to contentSkip to conversation

staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()

PATCH In review Fabio M. De Francesco 2 participants 6 messages Apr 13, 2021 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8192u: ieee80211: Replaced strncpy() with strscpy()

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.

---
 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +2 -2
index 25ea8e1b6b65..aa58eedf5e86 100644
@@ -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",
Signature · 1 line
2.31.1
#1 lore raw
Quoted 2 lines · Fabio M. De Francesco

Replaced strncpy() with strscpy() because of compilation time warnings about possible truncation of output [-Wstringop-truncation].

build warnings? What build warnings?

Quoted 13 lines

Furthermore, according to the Linux official documentation, strscpy() is preferred to strncpy.

---
 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -0
index 25ea8e1b6b65..aa58eedf5e86 100644

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee · line 1388

Quoted 5 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +1 -1
@@ -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?

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee · line 1393

Quoted 6 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +1 -1
 				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

#2 lore raw
Quoted 6 lines · CEST Greg Kroah-Hartman
Quoted 2 lines · Fabio M. De Francesco

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);

Quoted 21 lines
Quoted 21 lines

Furthermore, according to the Linux official documentation, strscpy() is
preferred to strncpy.

---

 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 25ea8e1b6b65..aa58eedf5e86 100644

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -0
@@ -1385,12 +1385,12 @@ inline void ieee80211_softmac_new_net(struct

ieee80211_device *ieee, struct ieee>

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -0
 			 * essid provided by the user.
 			 */
Quoted 9 lines

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee

Quoted 3 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -1
 			if (!ssidbroad) {
 
-				strncpy(tmp_ssid, ieee-

current_network.ssid, IW_ESSID_MAX_SIZE);

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c

Quoted 1 line
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +1 -0
+				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

Quoted 6 lines
Quoted 2 lines

tmp_ssid_len = ieee-

current_network.ssid_len;

Quoted 3 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -0
 			}
 			memcpy(&ieee->current_network, net, 

sizeof(struct

Quoted 3 lines

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c

Quoted 3 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -1
 			ieee80211_network));
 
-			strncpy(ieee->current_network.ssid, 

tmp_ssid, IW_ESSID_MAX_SIZE);

Quoted 1 line

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c

Quoted 1 line
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +1 -0
+			strscpy(ieee->current_network.ssid, 

tmp_ssid, IW_ESSID_MAX_SIZE);

Quoted 6 lines

Same here, are you sure?

thanks,

greg k-h

#3 lore raw
Quoted 5 lines · Fabio M. De Francesco
Quoted 4 lines · CEST Greg Kroah-Hartman
Quoted 2 lines · Fabio M. De Francesco

Replaced strncpy() with strscpy() because of compilation time warnings about possible truncation of output [-Wstringop-truncation].

Quoted 7 lines
Quoted 2 lines

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.

Quoted 28 lines
Quoted 28 lines
Quoted 18 lines

Furthermore, according to the Linux official documentation, strscpy() is
preferred to strncpy.

---

 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 25ea8e1b6b65..aa58eedf5e86 100644

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -0
@@ -1385,12 +1385,12 @@ inline void ieee80211_softmac_new_net(struct

ieee80211_device *ieee, struct ieee>

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee

Quoted 6 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -1
 			 * essid provided by the user.
 			 */
 
 			if (!ssidbroad) {
 
-				strncpy(tmp_ssid, ieee-

current_network.ssid, IW_ESSID_MAX_SIZE);

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c

Quoted 1 line
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +1 -0
+				strscpy(tmp_ssid, ieee-

current_network.ssid, IW_ESSID_MAX_SIZE);

Quoted 7 lines
Quoted 2 lines

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

#4 lore raw
Quoted 3 lines · CEST Greg Kroah-Hartman
Quoted 2 lines · Fabio M. De Francesco
Quoted 1 line · CEST Greg Kroah-Hartman

On Tue, Apr 13, 2021 at 02:30:41PM +0200, Fabio M. De Francesco

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

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]

Quoted 9 lines
Quoted 3 lines

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

Quoted 48 lines
Quoted 34 lines
Quoted 34 lines
Quoted 21 lines

Furthermore, according to the Linux official documentation, strscpy()
is
preferred to strncpy.

---

 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 25ea8e1b6b65..aa58eedf5e86 100644

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -0
@@ -1385,12 +1385,12 @@ inline void

ieee80211_softmac_new_net(struct
ieee80211_device *ieee, struct ieee>

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee

Quoted 6 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +0 -1
 			 * essid provided by the user.
 			 */
 
 			if (!ssidbroad) {
 
-				strncpy(tmp_ssid, ieee-

current_network.ssid, IW_ESSID_MAX_SIZE);

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c

Quoted 1 line
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +1 -0
+				strscpy(tmp_ssid, ieee-

current_network.ssid, IW_ESSID_MAX_SIZE);

Quoted 7 lines
Quoted 1 line

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

#5 lore raw
Quoted 19 lines · Fabio M. De Francesco
Quoted 3 lines · CEST Greg Kroah-Hartman
Quoted 2 lines · Fabio M. De Francesco
Quoted 1 line · CEST Greg Kroah-Hartman

On Tue, Apr 13, 2021 at 02:30:41PM +0200, Fabio M. De Francesco

Quoted 14 lines · wrote:
Quoted 13 lines
Quoted 5 lines
Quoted 3 lines

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);

Quoted 7 lines
Quoted 5 lines

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" :)

Quoted 5 lines

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