diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-05-26 18:48:27 +0100 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-05-26 18:48:27 +0100 |
| commit | bc4bc4b67eb8601e48e43b36ad4d57393d2cc382 (patch) | |
| tree | c4a96219da8e6494ee8119746ac9469ec3c3e84f /util | |
| parent | 0e1e0fd0e8a72f10f47adecbe3f2eec1280cd9fc (diff) | |
nvmutil: fix error exits
ii used to rely on errno for exit status, but this was flawed.
when removing it, i neglected to adjust the actual error exits,
setting errno accordingly. this patch should fix it. this is
important for scripts that use nvmutil, which may rely on its
error status upon exit.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 1910c974..5d174040 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -283,7 +283,7 @@ cmd_setmac(void) if (mac_updated) return; - errno = EINVAL; + errno = ECANCELED; err(EXIT_FAILURE, "Error updating MAC address"); } @@ -376,6 +376,11 @@ cmd_dump(void) printf("MAC (part %d): ", partnum); macf(partnum); hexdump(partnum); + + if (numInvalid > 1) { + errno = EINVAL; + err(EXIT_FAILURE, "dump: No valid checksums"); + } } } @@ -407,6 +412,7 @@ hexdump(int partnum) } } +/* WARNING: Cannot fail. Make sure the file is valid. */ void cmd_setchecksum(void) { @@ -420,22 +426,30 @@ cmd_setchecksum(void) void cmd_brick(void) { - if (goodChecksum(part)) + if (goodChecksum(part)) { setWord(NVM_CHECKSUM_WORD, part, ((word(NVM_CHECKSUM_WORD, part)) ^ 0xFF)); + } else { + errno = ECANCELED; + err(EXIT_FAILURE, "brick: Bad checksum in part %d", part); + } } void cmd_copy(void) { nvmPartChanged[part ^ 1] = goodChecksum(part); + if (!nvmPartChanged[part ^ 1]) { + errno = ECANCELED; + err(EXIT_FAILURE, "copy: Bad checksum in part %d", part); + } } void cmd_swap(void) { if(!(goodChecksum(0) || goodChecksum(1))) { - errno = EINVAL; - err(EXIT_FAILURE, "Invalid checksums"); + errno = ECANCELED; + err(EXIT_FAILURE, "swap: Bad checksums"); } gbe[0] ^= gbe[1]; @@ -502,8 +516,10 @@ xclose(int *fd) int saved_errno = errno; int rval = 0; - if (fd == NULL) + if (fd == NULL) { + errno = EBADF; err(EXIT_FAILURE, "xclose: null pointer"); + } if (*fd < 0) return; |
