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

CHANGES
apps/s_client.c
crypto/rand/rand_egd.c

diff --git a/CHANGES b/CHANGES
index bedad8ac04c0897ff7f5b441cfad5f535141af3e..fe69f8fdb2d6fe4bf19bdf74211d1cc86f794770 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,10 @@
 
  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 af8cb1a3f0dd13946b43fa8dbfc0a02cfe53171f..f72195e02d4dc9a108d238e6169af02f0989136e 100644 (file)
@@ -595,6 +595,8 @@ re_start:
        if (starttls_proto == 1)
                {
                BIO_read(sbio,mbuf,BUFSIZZ);
+               BIO_printf(sbio,"EHLO some.host.name\r\n");
+               BIO_read(sbio,mbuf,BUFSIZZ);
                BIO_printf(sbio,"STARTTLS\r\n");
                BIO_read(sbio,sbuf,BUFSIZZ);
                }
index 3ec2eabc2bab39dac47a036543e2ee31fee3a377..cd666abfcb625bee25ca2a1ad2be3d601427cc43 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
                    {