fs/cifs: suppress a string overflow warning
Subsystems (2)
PATCH 1/1 fs/cifs: suppress a string overflow warning
A powerpc build of cifs with gcc v8.2.0 produces this warning:
fs/cifs/cifssmb.c: In function ‘CIFSSMBNegotiate’:fs/cifs/cifssmb.c:605:3: warning: ‘strncpy’ writing 16 bytes into a region of size 1 overflows the destination [-Wstringop-overflow=]
strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Since we are already doing a strlen() on the source, change the strncpy to a memcpy().
--- fs/cifs/cifssmb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/cifs/cifssmb.c +7 -3
@@ -601,10 +601,14 @@ CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) } count =0 ; +/* +* We know that all the name entries in the protocols array +* are short (< 16 bytes anyway) and are NUL terminated. +*/ for (i =0 ; i <CIFS_NUM_PROT ; i++) { -strncpy (pSMB->DialectsArray+count, protocols[i].name,16 ); - count +=strlen (protocols[i].name) +1 ; -/* null at end of source and target buffers anyway */ +size_t len =strlen (protocols[i].name) +1 ; +memcpy (pSMB->DialectsArray+count, protocols[i].name, len); + count += len; }inc_rfc1001_len (pSMB, count); pSMB->ByteCount =cpu_to_le16 (count);
Signature · 5 lines
2.19.0.rc1 -- Cheers, Stephen Rothwell
Steve French
AppliedMerged into cifs-2.6.git for-next
Is the message annoying enough on powerpc to merit going into 4.19-rc3, presumably should wait for 4.20?
Quoted 44 lines · Stephen Rothwell
A powerpc build of cifs with gcc v8.2.0 produces this warning:
fs/cifs/cifssmb.c: In function ‘CIFSSMBNegotiate’:fs/cifs/cifssmb.c:605:3: warning: ‘strncpy’ writing 16 bytes into a region of size 1 overflows the destination [-Wstringop-overflow=]strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Since we are already doing a
strlen()on the source, change the strncpy to amemcpy().Signed-off-by Stephen Rothwell <[email protected]>--- fs/cifs/cifssmb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)fs/cifs/cifssmb.c +7
-4@@ -601,10 +601,14 @@ CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) } count =0 ; +/* +* We know that all the name entries in the protocols array +* are short (< 16 bytes anyway) and are NUL terminated. +*/ for (i =0 ; i <CIFS_NUM_PROT ; i++) { -strncpy (pSMB->DialectsArray+count, protocols[i].name,16 ); - count +=strlen (protocols[i].name) +1 ; -/* null at end of source and target buffers anyway */ +size_t len =strlen (protocols[i].name) +1 ; +memcpy (pSMB->DialectsArray+count, protocols[i].name, len); + count += len; }inc_rfc1001_len (pSMB, count); pSMB->ByteCount =cpu_to_le16 (count); --2.19.0.rc1
--
Cheers,
Stephen Rothwell
Signature · 3 lines
Thanks, Steve
Hi Steve,
Quoted 5 lines · On Mon, 3 Sep 2018 09:44:17 -0500 Steve French <[email protected]> wrote:
Merged into cifs-2.6.git for-next
Is the message annoying enough on powerpc to merit going into 4.19-rc3, presumably should wait for 4.20?
Up to you, but 4.20 is probably fine.
Signature · 2 lines
Cheers, Stephen Rothwell
ok - it looks like it will be a little simpler if I wait
Quoted 15 lines · Stephen Rothwell
Hi Steve,
Quoted 5 lines · On Mon, 3 Sep 2018 09:44:17 -0500 Steve French <[email protected]> wrote:
Merged into cifs-2.6.git for-next
Is the message annoying enough on powerpc to merit going into 4.19-rc3, presumably should wait for 4.20?
Up to you, but 4.20 is probably fine.
--
Cheers,
Stephen Rothwell
Signature · 3 lines
Thanks, Steve