Skip to content

Commit 943deb6

Browse files
GustavoARSilvaSteve French
authored andcommitted
cifs: Replace a couple of one-element arrays with flexible-array members
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array member in structs negotiate_req and extended_response, and refactor the rest of the code, accordingly. Also, make use of the DECLARE_FLEX_ARRAY() helper to declare flexible array member EncryptionKey in union u. This new helper allows for flexible-array members in unions. Change pointer notation to proper array notation in a call to memcpy() where flexible-array member DialectsArray is being used as destination argument. Important to mention is that doing a build before/after this patch results in no binary output differences. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1]. Link: KSPP/linux#79 Link: KSPP/linux#229 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 4659f01 commit 943deb6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

fs/cifs/cifspdu.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ put_bcc(__u16 count, struct smb_hdr *hdr)
483483
typedef struct negotiate_req {
484484
struct smb_hdr hdr; /* wct = 0 */
485485
__le16 ByteCount;
486-
unsigned char DialectsArray[1];
486+
unsigned char DialectsArray[];
487487
} __attribute__((packed)) NEGOTIATE_REQ;
488488

489489
#define MIN_TZ_ADJ (15 * 60) /* minimum grid for timezones in seconds */
@@ -508,13 +508,14 @@ typedef struct negotiate_rsp {
508508
__u8 EncryptionKeyLength;
509509
__u16 ByteCount;
510510
union {
511-
unsigned char EncryptionKey[1]; /* cap extended security off */
511+
/* cap extended security off */
512+
DECLARE_FLEX_ARRAY(unsigned char, EncryptionKey);
512513
/* followed by Domain name - if extended security is off */
513514
/* followed by 16 bytes of server GUID */
514515
/* then security blob if cap_extended_security negotiated */
515516
struct {
516517
unsigned char GUID[SMB1_CLIENT_GUID_SIZE];
517-
unsigned char SecurityBlob[1];
518+
unsigned char SecurityBlob[];
518519
} __attribute__((packed)) extended_response;
519520
} __attribute__((packed)) u;
520521
} __attribute__((packed)) NEGOTIATE_RSP;

fs/cifs/cifssmb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ CIFSSMBNegotiate(const unsigned int xid,
465465
for (i = 0; i < CIFS_NUM_PROT; i++) {
466466
size_t len = strlen(protocols[i].name) + 1;
467467

468-
memcpy(pSMB->DialectsArray+count, protocols[i].name, len);
468+
memcpy(&pSMB->DialectsArray[count], protocols[i].name, len);
469469
count += len;
470470
}
471471
inc_rfc1001_len(pSMB, count);

0 commit comments

Comments
 (0)