From 76f646088cfde89a2e041aa5aa55c4c6a51a6ea3 Mon Sep 17 00:00:00 2001 From: inglorion Date: Fri, 13 Mar 2020 15:27:33 -0700 Subject: Avoid zero-size VLA in cmd_dump_fmap.c Zero-size variable length arrays are undefined behavior. UBSan reported a zero-size VLA in futility/cmd_dump_fmap.c when running tests. This change fixes that by making sure the size of the VLA is at least 1. BUG=chromium:1058086 TEST=FEATURES="test" USE="llvm-next ubsan" emerge -e --nodeps vboot_reference BRANCH=none Change-Id: I3c0eee0359668ce2e1ec3c0724f243788161fb13 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2103436 Tested-by: Bob Haarman Reviewed-by: Manoj Gupta Reviewed-by: Julius Werner Commit-Queue: Manoj Gupta --- futility/cmd_dump_fmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'futility') diff --git a/futility/cmd_dump_fmap.c b/futility/cmd_dump_fmap.c index 48f9185c..ff7252c6 100644 --- a/futility/cmd_dump_fmap.c +++ b/futility/cmd_dump_fmap.c @@ -36,7 +36,8 @@ static int normal_fmap(const FmapHeader *fmh, int argc, char *argv[]) char buf[80]; /* DWR: magic number */ const FmapAreaHeader *ah; ah = (const FmapAreaHeader *) (fmh + 1); - char *extract_names[argc]; + /* Size must greater than 0, else behavior is undefined. */ + char *extract_names[argc >= 1 ? argc : 1]; char *outname = 0; memset(extract_names, 0, sizeof(extract_names)); -- cgit v1.2.1