diff options
author | Hung-Te Lin <hungte@chromium.org> | 2018-10-04 14:11:42 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-13 11:42:12 -0700 |
commit | 050f66f11e1879594d0705974daf1075863e1d21 (patch) | |
tree | d66e5798c16e13e7da5b2a02a5df81005561fa02 /futility/updater.c | |
parent | 00d4be66721b24903f977e770148179035254e19 (diff) | |
download | vboot-050f66f11e1879594d0705974daf1075863e1d21.tar.gz |
futility: updater: Add ASPRINTF macro
When calling `asprintf`, if the return value is negative value then the
strp parameter is not allocated. Updater will need to call asprintf very
often in future, and we should abort immediately if asprintf can't
allocate buffer, since that implies either we are running out of memory,
or the system has gone very wrong.
Instead of writing if (asprintf(...) < 0) { ERROR(); return...}
everywhere, it seems easier to just add a macro and abort as exit(1).
BUG=chromium:875551
TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility
BRANCH=None
Change-Id: I8ea5f6c22dcc8225bc53fbd54b4b41a928f84910
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1260803
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility/updater.c')
-rw-r--r-- | futility/updater.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/futility/updater.c b/futility/updater.c index e1ae0769..e52f27f7 100644 --- a/futility/updater.c +++ b/futility/updater.c @@ -283,15 +283,9 @@ static int host_flashrom(enum flashrom_ops op, const char *image_path, } /* TODO(hungte) In future we should link with flashrom directly. */ - r = asprintf(&command, "flashrom %s %s -p %s %s %s %s %s", op_cmd, - image_path, programmer, dash_i, section_name, ignore_lock, - postfix); - - if (r == -1) { - /* `command` will be not available. */ - ERROR("Cannot allocate memory for command to execute."); - return -1; - } + ASPRINTF(&command, "flashrom %s %s -p %s %s %s %s %s", op_cmd, + image_path, programmer, dash_i, section_name, ignore_lock, + postfix); if (verbose) printf("Executing: %s\n", command); @@ -1244,12 +1238,9 @@ static int cbfs_file_exists(const char *image_file, char *cmd; int r; - if (asprintf(&cmd, - "cbfstool '%s' print -r %s 2>/dev/null | grep -q '^%s '", - image_file, section_name, cbfs_entry_name) < 0) { - ERROR("Failed to allocate buffer."); - return 0; - } + ASPRINTF(&cmd, + "cbfstool '%s' print -r %s 2>/dev/null | grep -q '^%s '", + image_file, section_name, cbfs_entry_name); r = system(cmd); free(cmd); return !r; |