From ce02b596560ac8986fe1ca3d6570a88914cc870f Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 11 Apr 2018 09:09:46 +0200 Subject: [PATCH] stm32mon: terminate gracefully when failing to get commands list When the CMD_GETCMD transaction fails, terminate immediately rather than continuing and crashing when we use later the uninitialized 'erase' function. Signed-off-by: Vincent Palatin BRANCH=none BUG=b:77825616 TEST=flash Scarlet EC through CCD. Change-Id: Ia40107fe27d81fdb9ee8220f73f4215d936a41c1 Reviewed-on: https://chromium-review.googlesource.com/1006595 Commit-Ready: Vincent Palatin Tested-by: Vincent Palatin Reviewed-by: Aseda Aboagye Reviewed-by: Mary Ruthven --- util/stm32mon.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/stm32mon.c b/util/stm32mon.c index f5fe227fc6..860bcc8c56 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -525,6 +525,7 @@ int command_get_commands(int fd, struct stm32_def *chip) return 0; } + fprintf(stderr, "Cannot get bootloader command list.\n"); return -1; } @@ -1060,7 +1061,8 @@ int main(int argc, char **argv) if (!chip) goto terminate; - command_get_commands(ser, chip); + if (command_get_commands(ser, chip) < 0) + goto terminate; if (flags & FLAG_READ_UNPROTECT) command_read_unprotect(ser);