areguera / rpms / cockpit

Forked from rpms/cockpit 5 years ago
Clone

Blame SOURCES/0001-ws-Recover-from-interruptions-during-read.patch

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