diff options
author | Randall Spangler <rspangler@chromium.org> | 2016-09-09 10:17:32 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-09-15 16:16:12 -0700 |
commit | b56b5f8e06b4cc4d4105a8141b3d2b8647eedff6 (patch) | |
tree | b0e92569a8c46cdc2a7f97fba03192c970368916 /cgpt | |
parent | 8f400498c68098d024170ccbcb4b3018b3417799 (diff) | |
download | vboot-b56b5f8e06b4cc4d4105a8141b3d2b8647eedff6.tar.gz |
Fix more coverity warnings in utilities
Assorted minor code issues, which we should fix so any new errors stand
out more.
BUG=chromium:643769
BRANCH=none
TEST=make runtests
Change-Id: I8fcf0c51e33d5dc49f650f4069f1579091cf188d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/383713
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r-- | cgpt/cgpt_nor.c | 13 | ||||
-rw-r--r-- | cgpt/cgpt_wrapper.c | 16 | ||||
-rw-r--r-- | cgpt/cmd_find.c | 4 |
3 files changed, 25 insertions, 8 deletions
diff --git a/cgpt/cgpt_nor.c b/cgpt/cgpt_nor.c index d2e7eafa..f8b361f8 100644 --- a/cgpt/cgpt_nor.c +++ b/cgpt/cgpt_nor.c @@ -212,7 +212,8 @@ int ReadNorFlash(char *temp_dir_template) { ret++; int fd_flags = fcntl(1, F_GETFD); // Close stdout on exec so that flashrom does not muck up cgpt's output. - fcntl(1, F_SETFD, FD_CLOEXEC); + if (0 != fcntl(1, F_SETFD, FD_CLOEXEC)) + Warning("Can't stop flashrom from mucking up our output\n"); if (ForkExecL(temp_dir_template, FLASHROM_PATH, "-i", "RW_GPT:rw_gpt", "-r", NULL) != 0) { Error("Cannot exec flashrom to read from RW_GPT section.\n"); @@ -221,7 +222,9 @@ int ReadNorFlash(char *temp_dir_template) { ret = 0; } - fcntl(1, F_SETFD, fd_flags); + // Restore stdout flags + if (0 != fcntl(1, F_SETFD, fd_flags)) + Warning("Can't restore stdout flags\n"); return ret; } @@ -237,7 +240,8 @@ int WriteNorFlash(const char *dir) { int nr_fails = 0; int fd_flags = fcntl(1, F_GETFD); // Close stdout on exec so that flashrom does not muck up cgpt's output. - fcntl(1, F_SETFD, FD_CLOEXEC); + if (0 != fcntl(1, F_SETFD, FD_CLOEXEC)) + Warning("Can't stop flashrom from mucking up our output\n"); if (ForkExecL(dir, FLASHROM_PATH, "-i", "RW_GPT_PRIMARY:rw_gpt_1", "-w", "--fast-verify", NULL) != 0) { Warning("Cannot write the 1st half of rw_gpt back with flashrom.\n"); @@ -248,7 +252,8 @@ int WriteNorFlash(const char *dir) { Warning("Cannot write the 2nd half of rw_gpt back with flashrom.\n"); nr_fails++; } - fcntl(1, F_SETFD, fd_flags); + if (0 != fcntl(1, F_SETFD, fd_flags)) + Warning("Can't restore stdout flags\n"); switch (nr_fails) { case 0: ret = 0; break; case 1: Warning("It might still be okay.\n"); break; diff --git a/cgpt/cgpt_wrapper.c b/cgpt/cgpt_wrapper.c index 3903358e..f8dc2f4f 100644 --- a/cgpt/cgpt_wrapper.c +++ b/cgpt/cgpt_wrapper.c @@ -153,11 +153,14 @@ int main(int argc, const char *argv[]) { char resolved_cgpt[PATH_MAX]; pid_t pid = getpid(); char exe_link[40]; + int retval = 0; if (argc < 1) { return -1; } + const char *orig_argv0 = argv[0]; + snprintf(exe_link, sizeof(exe_link), "/proc/%d/exe", pid); memset(resolved_cgpt, 0, sizeof(resolved_cgpt)); if (readlink(exe_link, resolved_cgpt, sizeof(resolved_cgpt) - 1) == -1) { @@ -170,18 +173,25 @@ int main(int argc, const char *argv[]) { if (argc > 2 && !has_dash_D(argc, argv)) { const char *mtd_device = find_mtd_device(argc, argv); if (mtd_device) { - return wrap_cgpt(argc, argv, mtd_device); + retval = wrap_cgpt(argc, argv, mtd_device); + goto cleanup; } } // Forward to cgpt as-is. Real cgpt has been renamed cgpt.bin. char *real_cgpt; if (asprintf(&real_cgpt, "%s.bin", argv[0]) == -1) { - return -1; + retval = -1; + goto cleanup; } argv[0] = real_cgpt; if (execv(argv[0], (char * const *)argv) == -1) { err(-2, "execv(%s) failed", real_cgpt); } - return -2; + free(real_cgpt); + retval = -2; + +cleanup: + argv[0] = orig_argv0; + return retval; } diff --git a/cgpt/cmd_find.c b/cgpt/cmd_find.c index 3802902b..511518d5 100644 --- a/cgpt/cmd_find.c +++ b/cgpt/cmd_find.c @@ -46,8 +46,10 @@ static uint8_t *ReadFile(const char *filename, uint64_t *size) { fseek(f, 0, SEEK_END); pos = ftell(f); - if (pos < 0) + if (pos < 0) { + fclose(f); return NULL; + } *size = pos; rewind(f); |