All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cifs: using strlcpy instead of strncpy
@ 2013-06-20 10:56 Zhao Hongjiang
       [not found] ` <51C2DFD6.5070202-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Zhao Hongjiang @ 2013-06-20 10:56 UTC (permalink / raw)
  To: sfrench-eUNUBHrolfbYtjvyW6yDsg
  Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ

for NUL terminated string, need alway set '\0' in the end.

Signed-off-by: Zhao Hongjiang <zhaohongjiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 fs/cifs/connect.c |    2 +-
 fs/cifs/smb2pdu.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index e3bc39b..2ea78a3 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -3738,7 +3738,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
 		}
 		bcc_ptr += length + 1;
 		bytes_left -= (length + 1);
-		strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
+		strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
 
 		/* mostly informational -- no need to fail on error here */
 		kfree(tcon->nativeFileSystem);
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 2b95ce2..99bf768 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -792,7 +792,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
 	tcon->tidStatus = CifsGood;
 	tcon->need_reconnect = false;
 	tcon->tid = rsp->hdr.TreeId;
-	strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
+	strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
 
 	if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
 	    ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))
-- 
1.7.1

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

* Re: [PATCH] cifs: using strlcpy instead of strncpy
       [not found] ` <51C2DFD6.5070202-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2013-06-21 17:14   ` Jeff Layton
       [not found]     ` <20130621131453.70c88a9c-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
  2013-06-21 17:38   ` Steve French
  1 sibling, 1 reply; 4+ messages in thread
From: Jeff Layton @ 2013-06-21 17:14 UTC (permalink / raw)
  To: Zhao Hongjiang
  Cc: sfrench-eUNUBHrolfbYtjvyW6yDsg, linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ

On Thu, 20 Jun 2013 18:56:22 +0800
Zhao Hongjiang <zhaohongjiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> wrote:

> for NUL terminated string, need alway set '\0' in the end.
> 
> Signed-off-by: Zhao Hongjiang <zhaohongjiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> ---
>  fs/cifs/connect.c |    2 +-
>  fs/cifs/smb2pdu.c |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index e3bc39b..2ea78a3 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -3738,7 +3738,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
>  		}
>  		bcc_ptr += length + 1;
>  		bytes_left -= (length + 1);
> -		strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
> +		strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
>  
>  		/* mostly informational -- no need to fail on error here */
>  		kfree(tcon->nativeFileSystem);
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index 2b95ce2..99bf768 100644
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -792,7 +792,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
>  	tcon->tidStatus = CifsGood;
>  	tcon->need_reconnect = false;
>  	tcon->tid = rsp->hdr.TreeId;
> -	strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
> +	strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
>  
>  	if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
>  	    ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))

Seems like a reasonable cleanup, but if you're going to do that then
it might not hurt to convert most of the places where MAX_TREE_SIZE is
used to use sizeof(tcon->treeName) instead.

Either way...

Acked-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

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

* Re: [PATCH] cifs: using strlcpy instead of strncpy
       [not found] ` <51C2DFD6.5070202-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  2013-06-21 17:14   ` Jeff Layton
@ 2013-06-21 17:38   ` Steve French
  1 sibling, 0 replies; 4+ messages in thread
From: Steve French @ 2013-06-21 17:38 UTC (permalink / raw)
  To: Zhao Hongjiang
  Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ

I actually prefer his change.   He potentially fixes a bug changing
these two of six places where it is used and the other four places
MAX_TREE_SIZE is used are clear enough either way.

On Thu, Jun 20, 2013 at 5:56 AM, Zhao Hongjiang
<zhaohongjiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> wrote:
>
> for NUL terminated string, need alway set '\0' in the end.
>
> Signed-off-by: Zhao Hongjiang <zhaohongjiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> ---
>  fs/cifs/connect.c |    2 +-
>  fs/cifs/smb2pdu.c |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index e3bc39b..2ea78a3 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -3738,7 +3738,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
>                 }
>                 bcc_ptr += length + 1;
>                 bytes_left -= (length + 1);
> -               strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
> +               strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
>
>                 /* mostly informational -- no need to fail on error here */
>                 kfree(tcon->nativeFileSystem);
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index 2b95ce2..99bf768 100644
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -792,7 +792,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
>         tcon->tidStatus = CifsGood;
>         tcon->need_reconnect = false;
>         tcon->tid = rsp->hdr.TreeId;
> -       strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
> +       strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
>
>         if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
>             ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))
> --
> 1.7.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html




--
Thanks,

Steve

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

* Re: [PATCH] cifs: using strlcpy instead of strncpy
       [not found]     ` <20130621131453.70c88a9c-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
@ 2013-06-21 17:46       ` Steve French
  0 siblings, 0 replies; 4+ messages in thread
From: Steve French @ 2013-06-21 17:46 UTC (permalink / raw)
  To: Jeff Layton
  Cc: Zhao Hongjiang, sfrench-eUNUBHrolfbYtjvyW6yDsg,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ

merged into for-next cifs-2.6.git

On Fri, Jun 21, 2013 at 12:14 PM, Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> On Thu, 20 Jun 2013 18:56:22 +0800
> Zhao Hongjiang <zhaohongjiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> wrote:
>
>> for NUL terminated string, need alway set '\0' in the end.
>>
>> Signed-off-by: Zhao Hongjiang <zhaohongjiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
>> ---
>>  fs/cifs/connect.c |    2 +-
>>  fs/cifs/smb2pdu.c |    2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
>> index e3bc39b..2ea78a3 100644
>> --- a/fs/cifs/connect.c
>> +++ b/fs/cifs/connect.c
>> @@ -3738,7 +3738,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
>>               }
>>               bcc_ptr += length + 1;
>>               bytes_left -= (length + 1);
>> -             strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
>> +             strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
>>
>>               /* mostly informational -- no need to fail on error here */
>>               kfree(tcon->nativeFileSystem);
>> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
>> index 2b95ce2..99bf768 100644
>> --- a/fs/cifs/smb2pdu.c
>> +++ b/fs/cifs/smb2pdu.c
>> @@ -792,7 +792,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
>>       tcon->tidStatus = CifsGood;
>>       tcon->need_reconnect = false;
>>       tcon->tid = rsp->hdr.TreeId;
>> -     strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
>> +     strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
>>
>>       if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
>>           ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))
>
> Seems like a reasonable cleanup, but if you're going to do that then
> it might not hurt to convert most of the places where MAX_TREE_SIZE is
> used to use sizeof(tcon->treeName) instead.
>
> Either way...
>
> Acked-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>



-- 
Thanks,

Steve

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

end of thread, other threads:[~2013-06-21 17:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 10:56 [PATCH] cifs: using strlcpy instead of strncpy Zhao Hongjiang
     [not found] ` <51C2DFD6.5070202-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-21 17:14   ` Jeff Layton
     [not found]     ` <20130621131453.70c88a9c-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2013-06-21 17:46       ` Steve French
2013-06-21 17:38   ` Steve French

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.