[git commit] seedrng: use predefined strings where possible

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Wed Apr 20 13:43:00 UTC 2022


commit: https://git.busybox.net/busybox/commit/?id=ce9a345632786d5585044ed71ed4c98c305b918f
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

- Use predefined strings where possible.
- Open /dev/random with O_RDONLY for ioctl().

function                                             old     new   delta
seed_from_file_if_exists                             413     410      -3
.rodata                                           108407  108350     -57
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-60)             Total: -60 bytes
   text	   data	    bss	    dec	    hex	filename
 975979	   4227	   1816	 982022	  efc06	busybox_old
 975919	   4227	   1816	 981962	  efbca	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason at zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 util-linux/seedrng.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c
index bc6ae5cb4..49b9ab54b 100644
--- a/util-linux/seedrng.c
+++ b/util-linux/seedrng.c
@@ -79,7 +79,7 @@ static size_t determine_optimal_seed_len(void)
 	unsigned long poolsize;
 
 	if (open_read_close("/proc/sys/kernel/random/poolsize", poolsize_str, sizeof(poolsize_str) - 1) < 0) {
-		bb_perror_msg("unable to determine pool size, falling back to %u bits", MIN_SEED_LEN * 8);
+		bb_perror_msg("unable to determine pool size, assuming %u bits", MIN_SEED_LEN * 8);
 		return MIN_SEED_LEN;
 	}
 	poolsize = (bb_strtoul(poolsize_str, NULL, 10) + 7) / 8;
@@ -129,7 +129,7 @@ static int seed_rng(uint8_t *seed, size_t len, bool credit)
 	}
 	memcpy(req.buffer, seed, len);
 
-	random_fd = open("/dev/random", O_RDWR);
+	random_fd = open("/dev/random", O_RDONLY);
 	if (random_fd < 0)
 		return -1;
 	ret = ioctl(random_fd, RNDADDENTROPY, &req);
@@ -154,7 +154,7 @@ static int seed_from_file_if_exists(const char *filename, int dfd, bool credit,
 		return -1;
 	}
 	if ((unlink(filename) < 0 || fsync(dfd) < 0) && seed_len) {
-		bb_simple_perror_msg("unable to remove seed after reading, so not seeding");
+		bb_simple_perror_msg("unable to remove seed, so not seeding");
 		return -1;
 	} else if (!seed_len)
 		return 0;
@@ -205,14 +205,14 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[])
 
 	umask(0077);
 	if (getuid())
-		bb_simple_error_msg_and_die("this program requires root");
+		bb_simple_error_msg_and_die(bb_msg_you_must_be_root);
 
 	if (mkdir(seed_dir, 0700) < 0 && errno != EEXIST)
 		bb_simple_perror_msg_and_die("unable to create seed directory");
 
 	dfd = open(seed_dir, O_DIRECTORY | O_RDONLY);
 	if (dfd < 0 || flock(dfd, LOCK_EX) < 0) {
-		bb_simple_perror_msg("unable to open and lock seed directory");
+		bb_simple_perror_msg("unable to lock seed directory");
 		program_ret = 1;
 		goto out;
 	}


More information about the busybox-cvs mailing list