lib: Fix illegal use of 0-length arrays
authorVolker Lendecke <vl@samba.org>
Mon, 29 May 2017 19:13:16 +0000 (21:13 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 6 Jun 2017 16:36:06 +0000 (18:36 +0200)
Found and confirmed to work by albert chin (china@thewrittenword.com)

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/msghdr.c

index 4b88c1a565b83ed8a2d4328caa720328c2bb6c0d..fec544628443dcf7a24ecffa36ac943dcd2ddfe0 100644 (file)
@@ -37,13 +37,19 @@ ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
                        msg->msg_control = NULL;
                        msg->msg_controllen = 0;
                }
-               return 0;
+               /*
+                * C99 doesn't allow 0-length arrays
+                */
+               return 1;
        }
        if (num_fds > INT8_MAX) {
                return -1;
        }
        if ((msg == NULL) || (cmsg_space > bufsize)) {
-               return cmsg_space;
+               /*
+                * C99 doesn't allow 0-length arrays
+                */
+               return MAX(cmsg_space, 1);
        }
 
        msg->msg_control = buf;