From 4891d713fb1949fe5c869974b94018380d110363 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sat, 15 Jan 2022 13:38:18 +1100 Subject: [PATCH] bn_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. Upstream pull request: https://github.com/libtom/libtommath/pull/512 Signed-off-by: Arnout Vandecappelle --- lib/hcrypto/libtommath/bn_s_mp_rand_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hcrypto/libtommath/bn_s_mp_rand_platform.c b/lib/hcrypto/libtommath/bn_s_mp_rand_platform.c index 55c69390e..79879c350 100644 --- a/lib/hcrypto/libtommath/bn_s_mp_rand_platform.c +++ b/lib/hcrypto/libtommath/bn_s_mp_rand_platform.c @@ -96,7 +96,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;