Skip to content

Commit a5bdc72

Browse files
sfrothwellgregkh
authored andcommitted
fs/cifs: suppress a string overflow warning
[ Upstream commit bcfb84a ] 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(). Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3941dbe commit a5bdc72

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

fs/cifs/cifssmb.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,15 @@ CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses)
589589
}
590590

591591
count = 0;
592+
/*
593+
* We know that all the name entries in the protocols array
594+
* are short (< 16 bytes anyway) and are NUL terminated.
595+
*/
592596
for (i = 0; i < CIFS_NUM_PROT; i++) {
593-
strncpy(pSMB->DialectsArray+count, protocols[i].name, 16);
594-
count += strlen(protocols[i].name) + 1;
595-
/* null at end of source and target buffers anyway */
597+
size_t len = strlen(protocols[i].name) + 1;
598+
599+
memcpy(pSMB->DialectsArray+count, protocols[i].name, len);
600+
count += len;
596601
}
597602
inc_rfc1001_len(pSMB, count);
598603
pSMB->ByteCount = cpu_to_le16(count);

0 commit comments

Comments
 (0)