Skip to content

Commit 266b9fe

Browse files
GustavoARSilvasmfrench
authored andcommitted
cifs: cifspdu.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 ba55344 commit 266b9fe

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fs/cifs/cifspdu.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ typedef struct smb_com_writex_req {
10211021
__le16 ByteCount;
10221022
__u8 Pad; /* BB check for whether padded to DWORD
10231023
boundary and optimum performance here */
1024-
char Data[0];
1024+
char Data[];
10251025
} __attribute__((packed)) WRITEX_REQ;
10261026

10271027
typedef struct smb_com_write_req {
@@ -1041,7 +1041,7 @@ typedef struct smb_com_write_req {
10411041
__le16 ByteCount;
10421042
__u8 Pad; /* BB check for whether padded to DWORD
10431043
boundary and optimum performance here */
1044-
char Data[0];
1044+
char Data[];
10451045
} __attribute__((packed)) WRITE_REQ;
10461046

10471047
typedef struct smb_com_write_rsp {
@@ -1306,7 +1306,7 @@ typedef struct smb_com_ntransact_req {
13061306
/* SetupCount words follow then */
13071307
__le16 ByteCount;
13081308
__u8 Pad[3];
1309-
__u8 Parms[0];
1309+
__u8 Parms[];
13101310
} __attribute__((packed)) NTRANSACT_REQ;
13111311

13121312
typedef struct smb_com_ntransact_rsp {
@@ -1523,7 +1523,7 @@ struct file_notify_information {
15231523
__le32 NextEntryOffset;
15241524
__le32 Action;
15251525
__le32 FileNameLength;
1526-
__u8 FileName[0];
1526+
__u8 FileName[];
15271527
} __attribute__((packed));
15281528

15291529
/* For IO_REPARSE_TAG_SYMLINK */
@@ -1536,7 +1536,7 @@ struct reparse_symlink_data {
15361536
__le16 PrintNameOffset;
15371537
__le16 PrintNameLength;
15381538
__le32 Flags;
1539-
char PathBuffer[0];
1539+
char PathBuffer[];
15401540
} __attribute__((packed));
15411541

15421542
/* Flag above */
@@ -1553,7 +1553,7 @@ struct reparse_posix_data {
15531553
__le16 ReparseDataLength;
15541554
__u16 Reserved;
15551555
__le64 InodeType; /* LNK, FIFO, CHR etc. */
1556-
char PathBuffer[0];
1556+
char PathBuffer[];
15571557
} __attribute__((packed));
15581558

15591559
struct cifs_quota_data {
@@ -1762,7 +1762,7 @@ struct set_file_rename {
17621762
__le32 overwrite; /* 1 = overwrite dest */
17631763
__u32 root_fid; /* zero */
17641764
__le32 target_name_len;
1765-
char target_name[0]; /* Must be unicode */
1765+
char target_name[]; /* Must be unicode */
17661766
} __attribute__((packed));
17671767

17681768
struct smb_com_transaction2_sfi_req {
@@ -2451,7 +2451,7 @@ struct cifs_posix_acl { /* access conrol list (ACL) */
24512451
__le16 version;
24522452
__le16 access_entry_count; /* access ACL - count of entries */
24532453
__le16 default_entry_count; /* default ACL - count of entries */
2454-
struct cifs_posix_ace ace_array[0];
2454+
struct cifs_posix_ace ace_array[];
24552455
/* followed by
24562456
struct cifs_posix_ace default_ace_arraay[] */
24572457
} __attribute__((packed)); /* level 0x204 */
@@ -2757,7 +2757,7 @@ typedef struct file_xattr_info {
27572757
/* BB do we need another field for flags? BB */
27582758
__u32 xattr_name_len;
27592759
__u32 xattr_value_len;
2760-
char xattr_name[0];
2760+
char xattr_name[];
27612761
/* followed by xattr_value[xattr_value_len], no pad */
27622762
} __attribute__((packed)) FILE_XATTR_INFO; /* extended attribute info
27632763
level 0x205 */

0 commit comments

Comments
 (0)