Skip to content

Commit cff2def

Browse files
GustavoARSilvasmfrench
authored andcommitted
cifs: smb2pdu.h: Replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] KSPP#21 [3] commit 7649773 ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent dc92027 commit cff2def

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

fs/cifs/smb2pdu.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct smb2_symlink_err_rsp {
182182
__le16 PrintNameOffset;
183183
__le16 PrintNameLength;
184184
__le32 Flags;
185-
__u8 PathBuffer[0];
185+
__u8 PathBuffer[];
186186
} __packed;
187187

188188
/* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
@@ -210,7 +210,7 @@ struct share_redirect_error_context_rsp {
210210
__le16 Flags;
211211
__le16 TargetType;
212212
__le32 IPAddrCount;
213-
struct move_dst_ipaddr IpAddrMoveList[0];
213+
struct move_dst_ipaddr IpAddrMoveList[];
214214
/* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
215215
} __packed;
216216

@@ -326,7 +326,7 @@ struct smb2_netname_neg_context {
326326
__le16 ContextType; /* 0x100 */
327327
__le16 DataLength;
328328
__le32 Reserved;
329-
__le16 NetName[0]; /* hostname of target converted to UCS-2 */
329+
__le16 NetName[]; /* hostname of target converted to UCS-2 */
330330
} __packed;
331331

332332
#define POSIX_CTXT_DATA_LEN 16
@@ -421,13 +421,13 @@ struct tree_connect_contexts {
421421
__le16 ContextType;
422422
__le16 DataLength;
423423
__le32 Reserved;
424-
__u8 Data[0];
424+
__u8 Data[];
425425
} __packed;
426426

427427
/* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
428428
struct smb3_blob_data {
429429
__le16 BlobSize;
430-
__u8 BlobData[0];
430+
__u8 BlobData[];
431431
} __packed;
432432

433433
/* Valid values for Attr */
@@ -477,14 +477,14 @@ struct remoted_identity_tcon_context {
477477
__le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
478478
__le16 UserClaims; /* offset to BLOB_DATA struct */
479479
__le16 DeviceClaims; /* offset to BLOB_DATA struct */
480-
__u8 TicketInfo[0]; /* variable length buf - remoted identity data */
480+
__u8 TicketInfo[]; /* variable length buf - remoted identity data */
481481
} __packed;
482482

483483
struct smb2_tree_connect_req_extension {
484484
__le32 TreeConnectContextOffset;
485485
__le16 TreeConnectContextCount;
486486
__u8 Reserved[10];
487-
__u8 PathName[0]; /* variable sized array */
487+
__u8 PathName[]; /* variable sized array */
488488
/* followed by array of TreeConnectContexts */
489489
} __packed;
490490

@@ -689,7 +689,7 @@ struct smb2_create_req {
689689
__le16 NameLength;
690690
__le32 CreateContextsOffset;
691691
__le32 CreateContextsLength;
692-
__u8 Buffer[0];
692+
__u8 Buffer[];
693693
} __packed;
694694

695695
/*
@@ -727,7 +727,7 @@ struct create_context {
727727
__le16 Reserved;
728728
__le16 DataOffset;
729729
__le32 DataLength;
730-
__u8 Buffer[0];
730+
__u8 Buffer[];
731731
} __packed;
732732

733733
#define SMB2_LEASE_READ_CACHING_HE 0x01
@@ -869,7 +869,7 @@ struct crt_sd_ctxt {
869869
struct resume_key_req {
870870
char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
871871
__le32 ContextLength; /* MBZ */
872-
char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
872+
char Context[]; /* ignored, Windows sets to 4 bytes of zero */
873873
} __packed;
874874

875875
/* this goes in the ioctl buffer when doing a copychunk request */
@@ -931,15 +931,15 @@ struct reparse_data_buffer {
931931
__le32 ReparseTag;
932932
__le16 ReparseDataLength;
933933
__u16 Reserved;
934-
__u8 DataBuffer[0]; /* Variable Length */
934+
__u8 DataBuffer[]; /* Variable Length */
935935
} __packed;
936936

937937
struct reparse_guid_data_buffer {
938938
__le32 ReparseTag;
939939
__le16 ReparseDataLength;
940940
__u16 Reserved;
941941
__u8 ReparseGuid[16];
942-
__u8 DataBuffer[0]; /* Variable Length */
942+
__u8 DataBuffer[]; /* Variable Length */
943943
} __packed;
944944

945945
struct reparse_mount_point_data_buffer {
@@ -950,7 +950,7 @@ struct reparse_mount_point_data_buffer {
950950
__le16 SubstituteNameLength;
951951
__le16 PrintNameOffset;
952952
__le16 PrintNameLength;
953-
__u8 PathBuffer[0]; /* Variable Length */
953+
__u8 PathBuffer[]; /* Variable Length */
954954
} __packed;
955955

956956
#define SYMLINK_FLAG_RELATIVE 0x00000001
@@ -964,7 +964,7 @@ struct reparse_symlink_data_buffer {
964964
__le16 PrintNameOffset;
965965
__le16 PrintNameLength;
966966
__le32 Flags;
967-
__u8 PathBuffer[0]; /* Variable Length */
967+
__u8 PathBuffer[]; /* Variable Length */
968968
} __packed;
969969

970970
/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
@@ -1066,7 +1066,7 @@ struct smb2_ioctl_req {
10661066
__le32 MaxOutputResponse;
10671067
__le32 Flags;
10681068
__u32 Reserved2;
1069-
__u8 Buffer[0];
1069+
__u8 Buffer[];
10701070
} __packed;
10711071

10721072
struct smb2_ioctl_rsp {
@@ -1469,7 +1469,7 @@ struct smb3_fs_vol_info {
14691469
__le32 VolumeLabelLength; /* includes trailing null */
14701470
__u8 SupportsObjects; /* True if eg like NTFS, supports objects */
14711471
__u8 Reserved;
1472-
__u8 VolumeLabel[0]; /* variable len */
1472+
__u8 VolumeLabel[]; /* variable len */
14731473
} __packed;
14741474

14751475
/* partial list of QUERY INFO levels */
@@ -1531,7 +1531,7 @@ struct smb2_file_rename_info { /* encoding of request for level 10 */
15311531
__u8 Reserved[7];
15321532
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
15331533
__le32 FileNameLength;
1534-
char FileName[0]; /* New name to be assigned */
1534+
char FileName[]; /* New name to be assigned */
15351535
} __packed; /* level 10 Set */
15361536

15371537
struct smb2_file_link_info { /* encoding of request for level 11 */
@@ -1540,15 +1540,15 @@ struct smb2_file_link_info { /* encoding of request for level 11 */
15401540
__u8 Reserved[7];
15411541
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
15421542
__le32 FileNameLength;
1543-
char FileName[0]; /* Name to be assigned to new link */
1543+
char FileName[]; /* Name to be assigned to new link */
15441544
} __packed; /* level 11 Set */
15451545

15461546
struct smb2_file_full_ea_info { /* encoding of response for level 15 */
15471547
__le32 next_entry_offset;
15481548
__u8 flags;
15491549
__u8 ea_name_length;
15501550
__le16 ea_value_length;
1551-
char ea_data[0]; /* \0 terminated name plus value */
1551+
char ea_data[]; /* \0 terminated name plus value */
15521552
} __packed; /* level 15 Set */
15531553

15541554
/*

0 commit comments

Comments
 (0)