netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Larry Finger' <Larry.Finger@lwfinger.net>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>
Subject: RE: [PATCH 1/2] staging: rtl8192e: Fix compiler warning about strncpy
Date: Tue, 21 Aug 2018 13:41:59 +0000	[thread overview]
Message-ID: <f1dfc983495c41a7b9d048419aeebd4d@AcuMS.aculab.com> (raw)
In-Reply-To: <20180820175124.23863-2-Larry.Finger@lwfinger.net>

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)

  reply	other threads:[~2018-08-21 17:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=f1dfc983495c41a7b9d048419aeebd4d@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).