diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2020-05-25 15:49:43 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2020-05-25 15:49:43 +0000 |
commit | 5ce625e7c5642adeba16b429ba1752db1a5d7be7 (patch) | |
tree | 302bc073f2670faccebdbd94d62a18999450d60b /sys/arch/alpha | |
parent | bc8712ab4fd641aadc8101b3230acb05ff47cb86 (diff) |
make loadrandom() return 0 for success, -1 for failure. While here,
relax the fstat() check because the system will have left the file
in the right mode.
ok visa kettenis
Diffstat (limited to 'sys/arch/alpha')
-rw-r--r-- | sys/arch/alpha/stand/boot/boot.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/sys/arch/alpha/stand/boot/boot.c b/sys/arch/alpha/stand/boot/boot.c index cc570d44407..916d9ea3bc2 100644 --- a/sys/arch/alpha/stand/boot/boot.c +++ b/sys/arch/alpha/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.26 2020/05/25 15:00:23 deraadt Exp $ */ +/* $OpenBSD: boot.c,v 1.27 2020/05/25 15:49:41 deraadt Exp $ */ /* $NetBSD: boot.c,v 1.10 1997/01/18 01:58:33 cgd Exp $ */ /* @@ -43,6 +43,7 @@ #include <sys/param.h> #include <sys/exec.h> #include <sys/stat.h> +#include <sys/reboot.h> #define _KERNEL #include <sys/fcntl.h> #undef _KERNEL @@ -65,24 +66,29 @@ int debug; char rnddata[BOOTRANDOM_MAX]; struct rc4_ctx randomctx; -void +int loadrandom(char *name, char *buf, size_t buflen) { struct stat sb; - int fd, i; + int fd, i, error = 0; fd = open(name, O_RDONLY); if (fd == -1) { if (errno != EPERM) printf("cannot open %s: %s\n", name, strerror(errno)); - return; + return -1; } - if (fstat(fd, &sb) == -1 || sb.st_uid != 0 || !S_ISREG(sb.st_mode) || - (sb.st_mode & (S_IWOTH|S_IROTH))) - goto fail; - (void) read(fd, buf, buflen); -fail: + if (fstat(fd, &sb) == -1) { + error = -1; + goto done; + } + if (read(fd, buf, buflen) != buflen) { + error = -1; + goto done; + } +done: close(fd); + return (error); } int @@ -90,7 +96,7 @@ main() { char *name, **namep; u_int64_t entry; - int rc; + int rc, boothowto = 0; uint64_t marks[MARK_MAX]; #ifdef DEBUG struct rpb *r; @@ -120,7 +126,8 @@ main() } #endif - loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)); + if (loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)) == 0) + boothowto |= RB_GOODRANDOM; rc4_keysetup(&randomctx, rnddata, sizeof rnddata); rc4_skip(&randomctx, 1536); |