lib: Avoid declaring zero-length VLAs in various messaging functions
authorDimitry Andric <dimitry@andric.com>
Fri, 1 Jan 2021 17:25:48 +0000 (18:25 +0100)
committerKarolin Seeger <kseeger@samba.org>
Tue, 5 Jan 2021 11:50:11 +0000 (11:50 +0000)
commit6e6a16d88050ee7930f74e12615c0e046c3f9f77
tree68101b5111d6262ef77ce9f02faf1ff043141d02
parent6f4f529ddedfefae28a4476b33e9e1b556469786
lib: Avoid declaring zero-length VLAs in various messaging functions

In messaging_rec_create(), messaging_recv_cb() and
messaging_dispatch_rec(), variable length arrays of file descriptors are
declared using an incoming num_fds parameter.

However, there are several scenarios where num_fds can be zero, and
declaring a zero-length VLA is undefined behavior. This can lead to
segmentation faults and/or other crashes when compiling with recent
versions of clang at high optimization levels.

To avoid ever using zero as the length for these declarations, use
MAX(1, length) instead.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14605

Signed-off-by: Dimitry Andric <dimitry@andric.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Mon Jan  4 10:50:07 UTC 2021 on sn-devel-184

(cherry picked from commit 3e96c95d41e4ccd0bf43b3ee78af644e2bc32e30)
source3/lib/messages.c