Skip to content

Commit d272e01

Browse files
GustavoARSilvakees
authored andcommitted
ksmbd: replace 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 members in multiple structs in fs/ksmbd/smb_common.h and one in fs/ksmbd/smb2pdu.h. 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#242 Link: KSPP#79 Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Acked-by: Namjae Jeon <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/Y3OxronfaPYv9qGP@work
1 parent d662198 commit d272e01

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,7 +3438,7 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
34383438
goto free_conv_name;
34393439
}
34403440

3441-
struct_sz = readdir_info_level_struct_sz(info_level) - 1 + conv_len;
3441+
struct_sz = readdir_info_level_struct_sz(info_level) + conv_len;
34423442
next_entry_offset = ALIGN(struct_sz, KSMBD_DIR_INFO_ALIGNMENT);
34433443
d_info->last_entry_off_align = next_entry_offset - struct_sz;
34443444

@@ -3690,7 +3690,7 @@ static int reserve_populate_dentry(struct ksmbd_dir_info *d_info,
36903690
return -EOPNOTSUPP;
36913691

36923692
conv_len = (d_info->name_len + 1) * 2;
3693-
next_entry_offset = ALIGN(struct_sz - 1 + conv_len,
3693+
next_entry_offset = ALIGN(struct_sz + conv_len,
36943694
KSMBD_DIR_INFO_ALIGNMENT);
36953695

36963696
if (next_entry_offset > d_info->out_buf_len) {

fs/ksmbd/smb2pdu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ struct smb2_posix_info {
443443
/* SidBuffer contain two sids (UNIX user sid(16), UNIX group sid(16)) */
444444
u8 SidBuffer[32];
445445
__le32 name_len;
446-
u8 name[1];
446+
u8 name[];
447447
/*
448448
* var sized owner SID
449449
* var sized group SID

fs/ksmbd/smb_common.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,14 @@ struct file_directory_info {
277277
__le64 AllocationSize;
278278
__le32 ExtFileAttributes;
279279
__le32 FileNameLength;
280-
char FileName[1];
280+
char FileName[];
281281
} __packed; /* level 0x101 FF resp data */
282282

283283
struct file_names_info {
284284
__le32 NextEntryOffset;
285285
__u32 FileIndex;
286286
__le32 FileNameLength;
287-
char FileName[1];
287+
char FileName[];
288288
} __packed; /* level 0xc FF resp data */
289289

290290
struct file_full_directory_info {
@@ -299,7 +299,7 @@ struct file_full_directory_info {
299299
__le32 ExtFileAttributes;
300300
__le32 FileNameLength;
301301
__le32 EaSize;
302-
char FileName[1];
302+
char FileName[];
303303
} __packed; /* level 0x102 FF resp */
304304

305305
struct file_both_directory_info {
@@ -317,7 +317,7 @@ struct file_both_directory_info {
317317
__u8 ShortNameLength;
318318
__u8 Reserved;
319319
__u8 ShortName[24];
320-
char FileName[1];
320+
char FileName[];
321321
} __packed; /* level 0x104 FFrsp data */
322322

323323
struct file_id_both_directory_info {
@@ -337,7 +337,7 @@ struct file_id_both_directory_info {
337337
__u8 ShortName[24];
338338
__le16 Reserved2;
339339
__le64 UniqueId;
340-
char FileName[1];
340+
char FileName[];
341341
} __packed;
342342

343343
struct file_id_full_dir_info {
@@ -354,7 +354,7 @@ struct file_id_full_dir_info {
354354
__le32 EaSize; /* EA size */
355355
__le32 Reserved;
356356
__le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit*/
357-
char FileName[1];
357+
char FileName[];
358358
} __packed; /* level 0x105 FF rsp data */
359359

360360
struct smb_version_values {

0 commit comments

Comments
 (0)