mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-16 23:08:49 +02:00
util/nvmutil: don't use xopen() for urandom
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+13
-5
@@ -277,7 +277,6 @@ static uint8_t pad[GBE_PART_SIZE]; /* the file that wouldn't die */
|
|||||||
static uint16_t mac_buf[3];
|
static uint16_t mac_buf[3];
|
||||||
static off_t gbe_file_size;
|
static off_t gbe_file_size;
|
||||||
|
|
||||||
static struct stat gbe_st;
|
|
||||||
static int urandom_fd = -1;
|
static int urandom_fd = -1;
|
||||||
static int gbe_fd = -1;
|
static int gbe_fd = -1;
|
||||||
static size_t part;
|
static size_t part;
|
||||||
@@ -729,12 +728,15 @@ open_dev_urandom(void)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
rname = oldrandom;
|
rname = oldrandom;
|
||||||
xopen(&urandom_fd, rname, O_RDONLY | O_BINARY | O_NONBLOCK, &gbe_st);
|
if (open(rname, O_RDONLY | O_BINARY | O_NONBLOCK) == -1)
|
||||||
|
err(errno, "%s: could not open", rname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
open_gbe_file(void)
|
open_gbe_file(void)
|
||||||
{
|
{
|
||||||
|
struct stat gbe_st;
|
||||||
|
|
||||||
xopen(&gbe_fd, fname, command[cmd_index].flags | O_BINARY, &gbe_st);
|
xopen(&gbe_fd, fname, command[cmd_index].flags | O_BINARY, &gbe_st);
|
||||||
|
|
||||||
gbe_file_size = gbe_st.st_size;
|
gbe_file_size = gbe_st.st_size;
|
||||||
@@ -1138,11 +1140,16 @@ gbe_cat_buf(uint8_t *b)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
err(errno, "%s: cat", rname);
|
err(errno, "stdout: cat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A partial write is especially
|
||||||
|
* fatal, as it should already be
|
||||||
|
* prevented in rw_file_exact().
|
||||||
|
*/
|
||||||
if ((size_t)rval != GBE_PART_SIZE)
|
if ((size_t)rval != GBE_PART_SIZE)
|
||||||
err(errno, "%s: Partial read", rname);
|
err(errno, "stdout: cat: Partial write");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1377,7 +1384,8 @@ gbe_x_offset(size_t p, const char *f_op, const char *d_type,
|
|||||||
*
|
*
|
||||||
* This must only be used on files. It cannot
|
* This must only be used on files. It cannot
|
||||||
* be used on sockets or pipes, because 0-byte
|
* be used on sockets or pipes, because 0-byte
|
||||||
* reads are treated like fatal errors.
|
* reads are treated like fatal errors. This
|
||||||
|
* means that EOF is also considered fatal.
|
||||||
*/
|
*/
|
||||||
static ssize_t
|
static ssize_t
|
||||||
rw_file_exact(int fd, uint8_t *mem, size_t len,
|
rw_file_exact(int fd, uint8_t *mem, size_t len,
|
||||||
|
|||||||
Reference in New Issue
Block a user