[Libguestfs] [PATCH 3/3] urandom: Fail if /dev/urandom returns EOF.

Richard W.M. Jones rjones at redhat.com
Tue Nov 21 11:41:51 UTC 2017


This is an unexpected error, so fail hard instead of leaking
End_of_file exception.

Nothing that calls into the Urandom module expects or handles
End_of_file.
---
 customize/urandom.ml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/customize/urandom.ml b/customize/urandom.ml
index ff5d028d4..ce0e2cf65 100644
--- a/customize/urandom.ml
+++ b/customize/urandom.ml
@@ -27,13 +27,14 @@
 open Unix
 
 open Std_utils
+open Tools_utils
+open Common_gettext.Gettext
 
 let read_byte fd =
   let b = Bytes.make 1 ' ' in
   fun () ->
-    if read fd b 0 1 = 0 then (
-      raise End_of_file
-    );
+    if read fd b 0 1 = 0 then
+      error (f_"unexpected end of file while reading /dev/urandom");
     Char.code (Bytes.unsafe_get b 0)
 
 let urandom_bytes n =
-- 
2.13.2




More information about the Libguestfs mailing list