diff mbox series

fs/cifs: Replace one-element array with flexible-array member.

Message ID 1610615171-68296-1-git-send-email-abaci-bugfix@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series fs/cifs: Replace one-element array with flexible-array member. | expand

Commit Message

Abaci Team Jan. 14, 2021, 9:06 a.m. UTC
Fix the following coccicheck warning:

./fs/cifs/smb2pdu.h:1711:8-16: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/
process/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1509:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/
process/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1486:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/
process/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1478:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/
process/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1437:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1429:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/
process/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1389:26-31: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1389:26-31: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1366:6-12: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1330:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1319:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1299:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

./fs/cifs/smb2pdu.h:1284:8-14: WARNING use flexible-array
member instead(https://www.kernel.org/doc/html/latest/process
/deprecated.html#zero-length-and-one-element-arrays)

Reported-by: Abaci Robot<abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Zhong <abaci-bugfix@linux.alibaba.com>
---
 fs/cifs/smb2pdu.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Aurélien Aptel Jan. 14, 2021, 9:25 a.m. UTC | #1
Hi Jiapeng,

This will change the size returned by sizeof(). Have you checked that
this doesn't introduce off-by-one errors in all the sizeof() usage?

Cheers,
Steve French Jan. 17, 2021, 9:58 p.m. UTC | #2
Jiapeng,
Aurelien is correct, you should respin this patch and correct for
where it breaks the sizeof calculation.  For example your change:

struct smb2_lock_rsp {
@@ -1434,7 +1434,7 @@ struct smb2_query_directory_req {
        __le16 FileNameOffset;
        __le16 FileNameLength;
        __le32 OutputBufferLength;
-       __u8   Buffer[1];
+       __u8   Buffer[];
 } __packed;

would have the side effect of making the file name off by one:

smb2pdu.c-4654- req->FileNameOffset =
smb2pdu.c:4655:         cpu_to_le16(sizeof(struct
smb2_query_directory_req) - 1);

On Thu, Jan 14, 2021 at 3:26 AM Aurélien Aptel via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> Hi Jiapeng,
>
> This will change the size returned by sizeof(). Have you checked that
> this doesn't introduce off-by-one errors in all the sizeof() usage?
>
> Cheers,
> --
> Aurélien Aptel / SUSE Labs Samba Team
> GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
> SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
> GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)
>
>
Al Viro Jan. 18, 2021, 12:01 a.m. UTC | #3
On Sun, Jan 17, 2021 at 03:58:23PM -0600, Steve French wrote:
> Jiapeng,
> Aurelien is correct, you should respin this patch and correct for
> where it breaks the sizeof calculation.  For example your change:
> 
> struct smb2_lock_rsp {
> @@ -1434,7 +1434,7 @@ struct smb2_query_directory_req {
>         __le16 FileNameOffset;
>         __le16 FileNameLength;
>         __le32 OutputBufferLength;
> -       __u8   Buffer[1];
> +       __u8   Buffer[];
>  } __packed;
> 
> would have the side effect of making the file name off by one:
> 
> smb2pdu.c-4654- req->FileNameOffset =
> smb2pdu.c:4655:         cpu_to_le16(sizeof(struct
> smb2_query_directory_req) - 1);

FWIW, that sizeof() - 1 should've been offsetof()...
Steve French Jan. 18, 2021, 2:08 a.m. UTC | #4
On Sun, Jan 17, 2021 at 6:02 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Sun, Jan 17, 2021 at 03:58:23PM -0600, Steve French wrote:
> > Jiapeng,
> > Aurelien is correct, you should respin this patch and correct for
> > where it breaks the sizeof calculation.  For example your change:
> >
> > struct smb2_lock_rsp {
> > @@ -1434,7 +1434,7 @@ struct smb2_query_directory_req {
> >         __le16 FileNameOffset;
> >         __le16 FileNameLength;
> >         __le32 OutputBufferLength;
> > -       __u8   Buffer[1];
> > +       __u8   Buffer[];
> >  } __packed;
> >
> > would have the side effect of making the file name off by one:
> >
> > smb2pdu.c-4654- req->FileNameOffset =
> > smb2pdu.c:4655:         cpu_to_le16(sizeof(struct
> > smb2_query_directory_req) - 1);
>
> FWIW, that sizeof() - 1 should've been offsetof()...

agreed
diff mbox series

Patch

diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index 204a622..7c9ac5d 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -1289,7 +1289,7 @@  struct smb2_read_plain_req {
 	__le32 RemainingBytes;
 	__le16 ReadChannelInfoOffset;
 	__le16 ReadChannelInfoLength;
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 /* Read flags */
@@ -1304,7 +1304,7 @@  struct smb2_read_rsp {
 	__le32 DataLength;
 	__le32 DataRemaining;
 	__u32  Flags;
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 /* For write request Flags field below the following flags are defined: */
@@ -1324,7 +1324,7 @@  struct smb2_write_req {
 	__le16 WriteChannelInfoOffset;
 	__le16 WriteChannelInfoLength;
 	__le32 Flags;
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 struct smb2_write_rsp {
@@ -1335,7 +1335,7 @@  struct smb2_write_rsp {
 	__le32 DataLength;
 	__le32 DataRemaining;
 	__u32  Reserved2;
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 /* notify flags */
@@ -1371,7 +1371,7 @@  struct smb2_change_notify_rsp {
 	__le16	StructureSize;  /* Must be 9 */
 	__le16	OutputBufferOffset;
 	__le32	OutputBufferLength;
-	__u8	Buffer[1]; /* array of file notify structs */
+	__u8	Buffer[]; /* array of file notify structs */
 } __packed;
 
 #define SMB2_LOCKFLAG_SHARED_LOCK	0x0001
@@ -1394,7 +1394,7 @@  struct smb2_lock_req {
 	__u64  PersistentFileId; /* opaque endianness */
 	__u64  VolatileFileId; /* opaque endianness */
 	/* Followed by at least one */
-	struct smb2_lock_element locks[1];
+	struct smb2_lock_element locks[];
 } __packed;
 
 struct smb2_lock_rsp {
@@ -1434,7 +1434,7 @@  struct smb2_query_directory_req {
 	__le16 FileNameOffset;
 	__le16 FileNameLength;
 	__le32 OutputBufferLength;
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 struct smb2_query_directory_rsp {
@@ -1442,7 +1442,7 @@  struct smb2_query_directory_rsp {
 	__le16 StructureSize; /* Must be 9 */
 	__le16 OutputBufferOffset;
 	__le32 OutputBufferLength;
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 /* Possible InfoType values */
@@ -1483,7 +1483,7 @@  struct smb2_query_info_req {
 	__le32 Flags;
 	__u64  PersistentFileId; /* opaque endianness */
 	__u64  VolatileFileId; /* opaque endianness */
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 struct smb2_query_info_rsp {
@@ -1491,7 +1491,7 @@  struct smb2_query_info_rsp {
 	__le16 StructureSize; /* Must be 9 */
 	__le16 OutputBufferOffset;
 	__le32 OutputBufferLength;
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 /*
@@ -1514,7 +1514,7 @@  struct smb2_set_info_req {
 	__le32 AdditionalInformation;
 	__u64  PersistentFileId; /* opaque endianness */
 	__u64  VolatileFileId; /* opaque endianness */
-	__u8   Buffer[1];
+	__u8   Buffer[];
 } __packed;
 
 struct smb2_set_info_rsp {
@@ -1716,7 +1716,7 @@  struct smb2_file_all_info { /* data block encoding of response to level 18 */
 	__le32 Mode;
 	__le32 AlignmentRequirement;
 	__le32 FileNameLength;
-	char   FileName[1];
+	char   FileName[];
 } __packed; /* level 18 Query */
 
 struct smb2_file_eof_info { /* encoding of request for level 10 */