|
|
c09cc9 |
From 0a0250e8118c47ced529772758d49d6c5a60924f Mon Sep 17 00:00:00 2001
|
|
|
c09cc9 |
From: Dominik Perpeet <dperpeet@redhat.com>
|
|
|
c09cc9 |
Date: Mon, 1 Feb 2016 13:49:59 +0100
|
|
|
c09cc9 |
Subject: [PATCH] ws: Recover from interruptions during read
|
|
|
c09cc9 |
|
|
|
c09cc9 |
Reading crucial information needs to recover from interrupted and
|
|
|
c09cc9 |
partial reads.
|
|
|
c09cc9 |
|
|
|
c09cc9 |
Closes #3650
|
|
|
c09cc9 |
Reviewed-by: Stef Walter <stefw@redhat.com>
|
|
|
c09cc9 |
---
|
|
|
c09cc9 |
src/ws/cockpitauth.c | 18 +++++++++++++++++-
|
|
|
c09cc9 |
1 file changed, 17 insertions(+), 1 deletion(-)
|
|
|
c09cc9 |
|
|
|
c09cc9 |
diff --git a/src/ws/cockpitauth.c b/src/ws/cockpitauth.c
|
|
|
c09cc9 |
index f8f2f7d..e26d2a0 100644
|
|
|
c09cc9 |
--- a/src/ws/cockpitauth.c
|
|
|
c09cc9 |
+++ b/src/ws/cockpitauth.c
|
|
|
c09cc9 |
@@ -155,12 +155,28 @@ static void
|
|
|
c09cc9 |
cockpit_auth_init (CockpitAuth *self)
|
|
|
c09cc9 |
{
|
|
|
c09cc9 |
gint fd;
|
|
|
c09cc9 |
+ gint read_bytes;
|
|
|
c09cc9 |
+ gint read_result;
|
|
|
c09cc9 |
|
|
|
c09cc9 |
self->key = g_byte_array_new ();
|
|
|
c09cc9 |
g_byte_array_set_size (self->key, 128);
|
|
|
c09cc9 |
fd = g_open ("/dev/urandom", O_RDONLY, 0);
|
|
|
c09cc9 |
- if (fd < 0 || read (fd, self->key->data, 128) != 128)
|
|
|
c09cc9 |
+ if (fd < 0)
|
|
|
c09cc9 |
g_error ("couldn't read random key, startup aborted");
|
|
|
c09cc9 |
+ read_bytes = 0;
|
|
|
c09cc9 |
+ do
|
|
|
c09cc9 |
+ {
|
|
|
c09cc9 |
+ errno = 0;
|
|
|
c09cc9 |
+ read_result = read (fd, self->key->data + read_bytes, self->key->len - read_bytes);
|
|
|
c09cc9 |
+ if (read_result <= 0)
|
|
|
c09cc9 |
+ {
|
|
|
c09cc9 |
+ if (errno == EAGAIN || errno == EINTR)
|
|
|
c09cc9 |
+ continue;
|
|
|
c09cc9 |
+ g_error ("couldn't read random key, startup aborted");
|
|
|
c09cc9 |
+ }
|
|
|
c09cc9 |
+ read_bytes += read_result;
|
|
|
c09cc9 |
+ }
|
|
|
c09cc9 |
+ while (read_bytes < self->key->len);
|
|
|
c09cc9 |
close (fd);
|
|
|
c09cc9 |
|
|
|
c09cc9 |
self->authenticated = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
c09cc9 |
--
|
|
|
c09cc9 |
2.4.3
|
|
|
c09cc9 |
|