summaryrefslogtreecommitdiff
path: root/futility/updater_quirks.c
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-10-04 14:11:42 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-10-13 11:42:12 -0700
commit050f66f11e1879594d0705974daf1075863e1d21 (patch)
treed66e5798c16e13e7da5b2a02a5df81005561fa02 /futility/updater_quirks.c
parent00d4be66721b24903f977e770148179035254e19 (diff)
downloadvboot-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_quirks.c')
-rw-r--r--futility/updater_quirks.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/futility/updater_quirks.c b/futility/updater_quirks.c
index f3989e78..f625a74c 100644
--- a/futility/updater_quirks.c
+++ b/futility/updater_quirks.c
@@ -237,12 +237,10 @@ static const char *extract_cbfs_file(struct updater_config *cfg,
const char *output = create_temp_file(cfg);
char *command, *result;
- if (asprintf(&command, "cbfstool \"%s\" extract -r %s -n \"%s\" "
- "-f \"%s\" 2>&1", image_file, cbfs_region,
- cbfs_name, output) < 0) {
- ERROR("Failed to allocate internal buffer.");
- return NULL;
- }
+ ASPRINTF(&command, "cbfstool \"%s\" extract -r %s -n \"%s\" "
+ "-f \"%s\" 2>&1", image_file, cbfs_region,
+ cbfs_name, output);
+
result = host_shell(command);
free(command);
@@ -285,15 +283,12 @@ static int quirk_eve_smm_store(struct updater_config *cfg)
return -1;
/* crosreview.com/1165109: The offset is fixed at 0x1bf000. */
- if (asprintf(&command,
- "cbfstool \"%s\" remove -r %s -n \"%s\" 2>/dev/null; "
- "cbfstool \"%s\" add -r %s -n \"%s\" -f \"%s\" "
- " -t raw -b 0x1bf000", temp_image, FMAP_RW_LEGACY,
- smm_store_name, temp_image, FMAP_RW_LEGACY,
- smm_store_name, old_store) < 0) {
- ERROR("Failed to allocate internal buffer.");
- return -1;
- }
+ ASPRINTF(&command,
+ "cbfstool \"%s\" remove -r %s -n \"%s\" 2>/dev/null; "
+ "cbfstool \"%s\" add -r %s -n \"%s\" -f \"%s\" "
+ " -t raw -b 0x1bf000", temp_image, FMAP_RW_LEGACY,
+ smm_store_name, temp_image, FMAP_RW_LEGACY,
+ smm_store_name, old_store);
host_shell(command);
free(command);