History

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].

Gustavo A. R. Silva committed 3 years ago

Commit d272e011 parent d6621983 files · +9 −9Browse files

Unified · Split

3 files
  1. fs/ksmbd/smb2pdu.c +2 −2
  2. fs/ksmbd/smb2pdu.h +1 −1
  3. fs/ksmbd/smb_common.h +6 −6
fs/ksmbd/smb2pdu.c+2−2
@@ -3438,7 +3438,7 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level, · 3437 unmodified lines
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, · 245 unmodified lines
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+1−1
@@ -443,7 +443,7 @@ struct smb2_posix_info { · 442 unmodified lines
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+6−6
@@ -277,14 +277,14 @@ struct file_directory_info { · 276 unmodified lines
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 { · 8 unmodified lines
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 { · 11 unmodified lines
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 { · 13 unmodified lines
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 { · 10 unmodified lines
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 {