netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] staging: Fix some warnings from strncpy()
@ 2018-08-20 17:51 Larry Finger
  2018-08-20 17:51 ` [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy Larry Finger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Larry Finger @ 2018-08-20 17:51 UTC (permalink / raw)
  To: gregkh; +Cc: netdev, devel, Larry Finger

When the size argument in a call to strncpy() is the size of the
destimation, gcc8 issues a warning. These patches fix the potential
problem by replacing the strncpy() with strlcpy().

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>


Larry Finger (2):
  staging: rtl8192e: Fix compiler warning about strncpy
  staging: rtl8712u: Fix compiler warning about strncpy

 drivers/staging/rtl8192e/rtllib_softmac.c     | 4 ++--
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

-- 
2.18.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy
  2018-08-20 17:51 [PATCH 0/2] staging: Fix some warnings from strncpy() Larry Finger
@ 2018-08-20 17:51 ` Larry Finger
  2018-08-21 13:41   ` David Laight
  2018-08-20 17:51 ` [PATCH 2/2] staging: rtl8712u: " Larry Finger
  2018-08-27 17:48 ` [PATCH 0/2] staging: Fix some warnings from strncpy() Greg KH
  2 siblings, 1 reply; 5+ messages in thread
From: Larry Finger @ 2018-08-20 17:51 UTC (permalink / raw)
  To: gregkh; +Cc: netdev, devel, Larry Finger

When strncpy() is called with source and destination strings the same
length, gcc 8 warns that there may be an unterminated string. Using
strlcpy() rather than strncpy() forces a null at the end and quiets the
warning.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8192e/rtllib_softmac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 919231fec09c..95a8390cb7ac 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -1684,14 +1684,14 @@ inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
 			 * essid provided by the user.
 			 */
 			if (!ssidbroad) {
-				strncpy(tmp_ssid, ieee->current_network.ssid,
+				strlcpy(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 rtllib_network));
 			if (!ssidbroad) {
-				strncpy(ieee->current_network.ssid, tmp_ssid,
+				strlcpy(ieee->current_network.ssid, tmp_ssid,
 					IW_ESSID_MAX_SIZE);
 				ieee->current_network.ssid_len = tmp_ssid_len;
 			}
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] staging: rtl8712u: Fix compiler warning about strncpy
  2018-08-20 17:51 [PATCH 0/2] staging: Fix some warnings from strncpy() Larry Finger
  2018-08-20 17:51 ` [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy Larry Finger
@ 2018-08-20 17:51 ` Larry Finger
  2018-08-27 17:48 ` [PATCH 0/2] staging: Fix some warnings from strncpy() Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Larry Finger @ 2018-08-20 17:51 UTC (permalink / raw)
  To: gregkh; +Cc: netdev, devel, Larry Finger

When strncpy() is called with source and destination strings the same
length, gcc 8 warns that there may be an unterminated string. Using
strlcpy() rather than strncpy() forces a null at the end and quiets the
warning.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index c3ff7c3e6681..08e1c0957a07 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -1789,7 +1789,7 @@ static int r871x_wx_set_enc_ext(struct net_device *dev,
 		return -ENOMEM;
 	param->cmd = IEEE_CMD_SET_ENCRYPTION;
 	eth_broadcast_addr(param->sta_addr);
-	strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
+	strlcpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
 	if (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
 		param->u.crypt.set_tx = 0;
 	if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy
  2018-08-20 17:51 ` [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy Larry Finger
@ 2018-08-21 13:41   ` David Laight
  0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2018-08-21 13:41 UTC (permalink / raw)
  To: 'Larry Finger', gregkh@linuxfoundation.org
  Cc: netdev@vger.kernel.org, devel@driverdev.osuosl.org

From: Larry Finger
> Sent: 20 August 2018 18:51
> When strncpy() is called with source and destination strings the same
> length, gcc 8 warns that there may be an unterminated string. Using
> strlcpy() rather than strncpy() forces a null at the end and quiets the
> warning.
> 
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
> ---
>  drivers/staging/rtl8192e/rtllib_softmac.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
> index 919231fec09c..95a8390cb7ac 100644
> --- a/drivers/staging/rtl8192e/rtllib_softmac.c
> +++ b/drivers/staging/rtl8192e/rtllib_softmac.c
> @@ -1684,14 +1684,14 @@ inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
>  			 * essid provided by the user.
>  			 */
>  			if (!ssidbroad) {
> -				strncpy(tmp_ssid, ieee->current_network.ssid,
> +				strlcpy(tmp_ssid, ieee->current_network.ssid,
>  					IW_ESSID_MAX_SIZE);
>  				tmp_ssid_len = ieee->current_network.ssid_len;

If there is a length, why not use it?
Depending on where the data came from the length might need validating.
Depending on how tmp_ssid is used it might need zero filling.

>  			}
>  			memcpy(&ieee->current_network, net,
>  			       sizeof(struct rtllib_network));

Gah - should be sizeof(ieee->current_network).
Or better still a structure assignment.

>  			if (!ssidbroad) {
> -				strncpy(ieee->current_network.ssid, tmp_ssid,
> +				strlcpy(ieee->current_network.ssid, tmp_ssid,
>  					IW_ESSID_MAX_SIZE);
>  				ieee->current_network.ssid_len = tmp_ssid_len;

Hmmm... this looks like it is restoring the fields.
So why not have a temporary ssid buffer that is the size of the
actual buffer and user memcpy().

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] staging: Fix some warnings from strncpy()
  2018-08-20 17:51 [PATCH 0/2] staging: Fix some warnings from strncpy() Larry Finger
  2018-08-20 17:51 ` [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy Larry Finger
  2018-08-20 17:51 ` [PATCH 2/2] staging: rtl8712u: " Larry Finger
@ 2018-08-27 17:48 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2018-08-27 17:48 UTC (permalink / raw)
  To: Larry Finger; +Cc: devel, netdev

On Mon, Aug 20, 2018 at 12:51:22PM -0500, Larry Finger wrote:
> When the size argument in a call to strncpy() is the size of the
> destimation, gcc8 issues a warning. These patches fix the potential
> problem by replacing the strncpy() with strlcpy().
> 
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
> 
> 
> Larry Finger (2):
>   staging: rtl8192e: Fix compiler warning about strncpy
>   staging: rtl8712u: Fix compiler warning about strncpy
> 
>  drivers/staging/rtl8192e/rtllib_softmac.c     | 4 ++--
>  drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)

I'm guessing you will send a second set of this patch series, right?
This one is now dropped, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-27 21:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-20 17:51 [PATCH 0/2] staging: Fix some warnings from strncpy() Larry Finger
2018-08-20 17:51 ` [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy Larry Finger
2018-08-21 13:41   ` David Laight
2018-08-20 17:51 ` [PATCH 2/2] staging: rtl8712u: " Larry Finger
2018-08-27 17:48 ` [PATCH 0/2] staging: Fix some warnings from strncpy() Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).