Commit 528fdb04d6deb060c9117dc4a84ebd5c0889b970

arnout 2021-09-21T14:37:52

s_mp_rand_platform.c: s_read_urandom: correctly handle split read s_read_urandom has a while loop to handle read() that returns less than the full buffer (either due to EINTR or because more than the atomic guarantee from urandom was requested). However, the target of the read was always the base pointer p instead of the updated pointer q, so in the end less than the requested randomness is returned. Use q instead of p in the read() call. Signed-off-by: Arnout Vandecappelle <arnout@mind.be>

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/s_mp_rand_platform.c b/s_mp_rand_platform.c
index 06b2f1b..0a6982a 100644
--- a/s_mp_rand_platform.c
+++ b/s_mp_rand_platform.c
@@ -95,7 +95,7 @@ static mp_err s_read_urandom(void *p, size_t n)
    if (fd == -1) return MP_ERR;
 
    while (n > 0u) {
-      ssize_t ret = read(fd, p, n);
+      ssize_t ret = read(fd, q, n);
       if (ret < 0) {
          if (errno == EINTR) {
             continue;