diff options
author | inglorion <inglorion@chromium.org> | 2020-03-13 15:27:33 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-03-18 06:10:58 +0000 |
commit | 76f646088cfde89a2e041aa5aa55c4c6a51a6ea3 (patch) | |
tree | 67b57ec64379c30ce6f93f03e5bebc67f9f8d7b0 /futility | |
parent | 17aaeace515d09255effbf9be93e323ce62879ce (diff) | |
download | vboot-76f646088cfde89a2e041aa5aa55c4c6a51a6ea3.tar.gz |
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 <inglorion@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
Diffstat (limited to 'futility')
-rw-r--r-- | futility/cmd_dump_fmap.c | 3 |
1 files changed, 2 insertions, 1 deletions
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)); |