diff options
| -rw-r--r-- | util/libreboot-utils/include/common.h | 2 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/mkhtemp.c | 13 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/num.c | 2 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/rand.c | 18 |
4 files changed, 9 insertions, 26 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index fb3aa886..98fcfc27 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -384,7 +384,7 @@ int dcat(const char *s, size_t n, */ unsigned short hextonum(char ch_s); -size_t rlong(void); +void rset(void *buf, size_t n); /* Helper functions for command: dump */ diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c index d22f526a..d32d8de4 100644 --- a/util/libreboot-utils/lib/mkhtemp.c +++ b/util/libreboot-utils/lib/mkhtemp.c @@ -635,12 +635,6 @@ mkhtemp(int *fd, p, xc, fd, st, type); if (r == 0) { - if (retries >= MKHTEMP_SPIN_THRESHOLD) { - /* usleep can return EINTR */ - close_errno = errno; - usleep((useconds_t)rlong() & 0x3FF); - errno = close_errno; - } continue; } if (r < 0) @@ -903,12 +897,7 @@ mkhtemp_fill_random(char *p, size_t xc) for (chx = 0; chx < xc; chx++) { retry_rand: - /* /dev/urandom if enabled, OR: - * on bsd: uses arc4random - * on linux: uses getrandom - NOTE: *aborts* on error, regardless of method - */ - r = rlong(); /* always *returns* successfully */ + rset(&r, sizeof(r)); if (r >= limit) goto retry_rand; diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c index 41a08f0b..92710c35 100644 --- a/util/libreboot-utils/lib/num.c +++ b/util/libreboot-utils/lib/num.c @@ -84,7 +84,7 @@ hextonum(char ch_s) if (ch == '?' || ch == 'x') { - rval = rlong(); + rset(&rval, sizeof(rval)); if (errno > 0) goto err_hextonum; diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index baaa28d6..9cb52386 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -29,23 +29,21 @@ #include "../include/common.h" -size_t -rlong(void) +void +rset(void *buf, size_t n) { int saved_errno = errno; - size_t len = sizeof(size_t); #if (defined(__OpenBSD__) || defined(__FreeBSD__) || \ defined(__NetBSD__) || defined(__APPLE__) || \ defined(__DragonFly__)) && !(defined(USE_URANDOM) && \ ((USE_URANDOM) > 0)) - arc4random_buf(&rval, len); + arc4random_buf(buf, n); goto out; #else size_t off = errno = 0; ssize_t rc = 0; - size_t rval; #if defined(USE_URANDOM) && \ ((USE_URANDOM) > 0) @@ -54,11 +52,11 @@ rlong(void) if ((fd = open("/dev/urandom", O_RDONLY)) < 0) goto err; retry_rand: - if ((rc = read(fd, &rval, len)) < 0) { + if ((rc = read(fd, buf, n)) < 0) { #elif defined(__linux__) retry_rand: if ((rc = (ssize_t)syscall(SYS_getrandom, - (char *)&rval + off, len - off, 0)) < 0) { + buf + off, n - off, 0)) < 0) { #else #error Unsupported operating system (possibly unsecure randomisation) #endif @@ -72,21 +70,17 @@ retry_rand: goto err; /* possibly unsupported by kernel */ } - if ((off += (size_t)rc) < len) + if ((off += (size_t)rc) < n) goto retry_rand; goto out; - err: err_no_cleanup(1, ECANCELED, "Randomisation failure, possibly unsupported in your kernel."); exit(EXIT_FAILURE); - - return 0; #endif out: errno = saved_errno; - return rval; } #endif |
