util/nvmutil: code cleanup (pledge/unveil calls)
Signed-off-by: Leah Rowe <leah@libreboot.org>fsdg20230625
parent
69fa333e25
commit
99258a38ae
|
@ -18,7 +18,6 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
if (strcmp(COMMAND, "dump") == 0) {
|
if (strcmp(COMMAND, "dump") == 0) {
|
||||||
xpledge("stdio", NULL);
|
|
||||||
cmd = &cmd_dump;
|
cmd = &cmd_dump;
|
||||||
} else if (strcmp(COMMAND, "setmac") == 0) {
|
} else if (strcmp(COMMAND, "setmac") == 0) {
|
||||||
strMac = (char *) strRMac; /* random mac address */
|
strMac = (char *) strRMac; /* random mac address */
|
||||||
|
@ -41,7 +40,6 @@ main(int argc, char *argv[])
|
||||||
nf = SIZE_4KB;
|
nf = SIZE_4KB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err_if((errno = ((strMac == NULL) && (cmd == NULL)) ? EINVAL : errno));
|
err_if((errno = ((strMac == NULL) && (cmd == NULL)) ? EINVAL : errno));
|
||||||
|
|
||||||
skipread[part ^ 1] = (cmd == &cmd_copy) | (cmd == &cmd_setchecksum)
|
skipread[part ^ 1] = (cmd == &cmd_copy) | (cmd == &cmd_setchecksum)
|
||||||
|
@ -61,10 +59,11 @@ main(int argc, char *argv[])
|
||||||
void
|
void
|
||||||
openFiles(const char *path)
|
openFiles(const char *path)
|
||||||
{
|
{
|
||||||
(void)rhex();
|
struct stat st;
|
||||||
xopen(fd, path, flags);
|
xopen(fd, path, flags);
|
||||||
if ((st.st_size != SIZE_8KB))
|
if ((st.st_size != SIZE_8KB))
|
||||||
err(errno = ECANCELED, "File `%s` not 8KiB", path);
|
err(errno = ECANCELED, "File `%s` not 8KiB", path);
|
||||||
|
xopen(rfd, "/dev/urandom", O_RDONLY);
|
||||||
errno = errno != ENOTDIR ? errno : 0;
|
errno = errno != ENOTDIR ? errno : 0;
|
||||||
xunveil("/dev/urandom", "r");
|
xunveil("/dev/urandom", "r");
|
||||||
if (flags != O_RDONLY) {
|
if (flags != O_RDONLY) {
|
||||||
|
@ -145,14 +144,10 @@ hextonum(char ch)
|
||||||
uint8_t
|
uint8_t
|
||||||
rhex(void)
|
rhex(void)
|
||||||
{
|
{
|
||||||
static int rfd = -1, n = 0;
|
static int n = 0;
|
||||||
static uint8_t rnum[16];
|
static uint8_t rnum[16];
|
||||||
if (!n) {
|
if (!n)
|
||||||
if (rfd == -1) {
|
|
||||||
xopen(rfd, "/dev/urandom", O_RDONLY);
|
|
||||||
}
|
|
||||||
xpread(rfd, (uint8_t *) &rnum, (n = 15) + 1, 0, "/dev/urandom");
|
xpread(rfd, (uint8_t *) &rnum, (n = 15) + 1, 0, "/dev/urandom");
|
||||||
}
|
|
||||||
return rnum[n--] & 0xf;
|
return rnum[n--] & 0xf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ uint8_t *buf = (uint8_t *) &buf16;
|
||||||
size_t nf = 128, gbe[2];
|
size_t nf = 128, gbe[2];
|
||||||
uint8_t skipread[2] = {0, 0};
|
uint8_t skipread[2] = {0, 0};
|
||||||
|
|
||||||
int flags = O_RDWR, fd = -1, part, gbeFileModified = 0;
|
int flags = O_RDWR, rfd, fd, part, gbeFileModified = 0;
|
||||||
uint8_t nvmPartModified[2] = {0, 0};
|
uint8_t nvmPartModified[2] = {0, 0};
|
||||||
|
|
||||||
int test = 1;
|
int test = 1;
|
||||||
|
@ -54,7 +54,7 @@ int big_endian;
|
||||||
|
|
||||||
#define xopen(f,l,p) if (opendir(l) != NULL) err(errno = EISDIR, "%s", l); \
|
#define xopen(f,l,p) if (opendir(l) != NULL) err(errno = EISDIR, "%s", l); \
|
||||||
if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
|
if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
|
||||||
struct stat st; if (fstat(f, &st) == -1) err(ERR(), "%s", l)
|
if (fstat(f, &st) == -1) err(ERR(), "%s", l)
|
||||||
#define xpread(f, b, n, o, l) if (pread(f, b, n, o) == -1) err(ERR(), "%s", l)
|
#define xpread(f, b, n, o, l) if (pread(f, b, n, o) == -1) err(ERR(), "%s", l)
|
||||||
#define handle_endianness() if (big_endian) xorswap_buf(p)
|
#define handle_endianness() if (big_endian) xorswap_buf(p)
|
||||||
#define xpwrite(f, b, n, o, l) if (pwrite(f, b, n, o) == -1) err(ERR(), "%s", l)
|
#define xpwrite(f, b, n, o, l) if (pwrite(f, b, n, o) == -1) err(ERR(), "%s", l)
|
||||||
|
|
Loading…
Reference in New Issue