From: Taylor R Campbell Date: Wed, 7 Nov 2018 17:06:50 +0000 (+0000) Subject: Remember to close /dev/urandom when done. X-Git-Tag: mit-scheme-pucked-10.1.2~16^2~116^2~23 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=2784ef78b9024a280168efb0697580373fe364e9;p=mit-scheme.git Remember to close /dev/urandom when done. --- 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); }