urandom: Fail if /dev/urandom returns EOF.

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.
This commit is contained in:
Richard W.M. Jones
2017-11-21 11:39:40 +00:00
parent fd0bfba7b2
commit c2898c50fd

View File

@@ -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 =