Fix hang in EGD/PRNGD query when communication socket is closed
authorLutz Jänicke <jaenicke@openssl.org>
Sat, 19 Feb 2005 10:19:07 +0000 (10:19 +0000)
committerLutz Jänicke <jaenicke@openssl.org>
Sat, 19 Feb 2005 10:19:07 +0000 (10:19 +0000)
prematurely by EGD/PRNGD.
PR: 1014
Submitted by: Darren Tucker <dtucker@zip.com.au>

CHANGES
crypto/rand/rand_egd.c

diff --git a/CHANGES b/CHANGES
index 28b0e29514820d71de2addb4c3f832b9387f6afc..4d766fb2f210d9099ff797a46fc0cf265daa9a7a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 
  Changes between 0.9.7e and 0.9.7f  [XX xxx XXXX]
 
+  *) Fix hang in EGD/PRNGD query when communication socket is closed
+     prematurely by EGD/PRNGD.
+     [Darren Tucker <dtucker@zip.com.au> via Lutz Jänicke, resolves #1014]
+
   *) Prompt for pass phrases when appropriate for PKCS12 input format.
      [Steve Henson]
 
index e34f07c5e8307a8123ec646f77a167f0f85eebfa..50bce6cabae8a649bd45b456d9164fb0a678635f 100644 (file)
@@ -216,7 +216,9 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
            while (numbytes != 1)
                {
                num = read(fd, egdbuf, 1);
-               if (num >= 0)
+               if (num == 0)
+                       goto err;       /* descriptor closed */
+               else if (num > 0)
                    numbytes += num;
                else
                    {
@@ -246,7 +248,9 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
            while (numbytes != egdbuf[0])
                {
                num = read(fd, retrievebuf + numbytes, egdbuf[0] - numbytes);
-               if (num >= 0)
+               if (num == 0)
+                       goto err;       /* descriptor closed */
+               else if (num > 0)
                    numbytes += num;
                else
                    {