diff options
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/Makefile | 2 | ||||
| -rw-r--r-- | util/nvmutil/nvmutil.c | 23 |
2 files changed, 15 insertions, 10 deletions
diff --git a/util/nvmutil/Makefile b/util/nvmutil/Makefile index 7c7411f9..e8350203 100644 --- a/util/nvmutil/Makefile +++ b/util/nvmutil/Makefile @@ -3,7 +3,7 @@ # SPDX-FileCopyrightText: 2023 Riku Viitanen <riku.viitanen@protonmail.com> CC?=cc -CFLAGS?=-Os -Wall -Wextra -Werror -pedantic +CFLAGS?=-Os -Wall -Wextra DESTDIR?= PREFIX?=/usr/local INSTALL?=install diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 1f211d6c..1910c974 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: MIT */ -/* Copyright (c) 2022-2025 Leah Rowe <leah@libreboot.org> */ +/* Copyright (c) 2022-2026 Leah Rowe <leah@libreboot.org> */ /* Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com> */ #include <sys/types.h> @@ -55,7 +55,8 @@ uint8_t hextonum(char chs), rhex(void); uint16_t mac[3] = {0, 0, 0}; ssize_t nf; -size_t partsize, gbe[2]; +size_t partsize; +uintptr_t gbe[2]; uint8_t nvmPartChanged[2] = {0, 0}, do_read[2] = {1, 1}; int flags, rfd, fd, part; @@ -94,8 +95,8 @@ void (*cmd)(void) = NULL; #define reset_caller_errno(return_value) \ do { \ - if (SUCCESS(return_value) && (!errno)) \ - errno = saved_errno; \ + if (SUCCESS(return_value) && (!errno)) \ + errno = saved_errno; \ } while (0) int @@ -199,6 +200,7 @@ openFiles(const char *path) { struct stat st; + xopen(rfd, "/dev/urandom", O_RDONLY); xopen(fd, path, flags); switch(st.st_size) { @@ -213,7 +215,8 @@ openFiles(const char *path) break; } - xopen(rfd, "/dev/urandom", O_RDONLY); + if (if_err(!S_ISREG(st.st_mode), EBADF)) + err(EXIT_FAILURE, "Not a GbE file"); } void @@ -231,7 +234,7 @@ readGbe(void) if (buf == NULL) err(EXIT_FAILURE, "malloc"); - gbe[0] = (size_t) buf; + gbe[0] = (uintptr_t) buf; gbe[1] = gbe[0] + (nf * (do_read[0] & do_read[1])); ssize_t tnr = 0; @@ -430,8 +433,10 @@ cmd_copy(void) void cmd_swap(void) { - err_if(!(goodChecksum(0) || goodChecksum(1))); - errno = 0; + if(!(goodChecksum(0) || goodChecksum(1))) { + errno = EINVAL; + err(EXIT_FAILURE, "Invalid checksums"); + } gbe[0] ^= gbe[1]; gbe[1] ^= gbe[0]; @@ -469,7 +474,7 @@ writeGbe(void) err_if(nw == -1); if (nw != nf) { errno = ECANCELED; - err(EXIT_SUCCESS, + err(EXIT_FAILURE, "%ld bytes written to '%s', expected %ld bytes\n", nw, filename, nf); } |
