From 2784ef78b9024a280168efb0697580373fe364e9 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 7 Nov 2018 17:06:50 +0000 Subject: [PATCH] Remember to close /dev/urandom when done. --- src/microcode/uxentropy.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/microcode/uxentropy.c b/src/microcode/uxentropy.c index 057d92743..2bc4a810c 100644 --- a/src/microcode/uxentropy.c +++ b/src/microcode/uxentropy.c @@ -31,11 +31,21 @@ USA. #define PATH_URANDOM "/dev/urandom" +static void +tx_close (void * cookie) +{ + int * fdp = cookie; + if ((*fdp) != -1) + (void) UX_close (*fdp); +} + void OS_get_entropy (uint8_t buf [32]) { size_t nbytes = 32; - int fd; + int fd = -1; + transaction_begin (); + transaction_record_action (tat_always, tx_close, (&fd)); STD_FD_SYSTEM_CALL (syscall_open, fd, (UX_open (PATH_URANDOM, O_RDONLY))); ssize_t nread; while ((nread = (UX_read (fd, buf, nbytes))) != 0) @@ -46,7 +56,10 @@ OS_get_entropy (uint8_t buf [32]) continue; } if (((size_t) nread) >= nbytes) - return; + { + transaction_commit (); + return; + } nbytes -= ((size_t) nread); buf += ((size_t) nread); } -- 2.25.1