blob: 5b69e5c88fb75d17d766f1c297b1d6c821304aec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
From 469b41ac89b9f6772ea31df8379669d205be95f8 Mon Sep 17 00:00:00 2001
From: Nuno Silva <nuno.m.ribeiro.silva@tecnico.ulisboa.pt>
Date: Mon, 24 Aug 2020 19:34:53 +0100
Subject: [PATCH] common: fix infinite loop when getrandom fails
Fixes: https://github.com/iputils/iputils/issues/291
---
iputils_common.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/iputils_common.c b/iputils_common.c
index 58eacd0..c41f201 100644
--- a/iputils_common.c
+++ b/iputils_common.c
@@ -98,18 +98,24 @@ static unsigned int iputil_srand_fallback(void)
void iputils_srand(void)
{
unsigned int i;
+
#if HAVE_GETRANDOM
ssize_t ret;
- while ((ret = getrandom(&i, sizeof(i), GRND_NONBLOCK)) != sizeof(i)) {
- switch(errno) {
+ do {
+ errno = 0;
+ ret = getrandom(&i, sizeof(i), GRND_NONBLOCK);
+ switch (errno) {
+ case 0:
+ break;
case EINTR:
continue;
default:
i = iputil_srand_fallback();
- break;
+ goto done;
}
- }
+ } while (ret != sizeof(i));
+ done:
#else
i = iputil_srand_fallback();
#endif
|