Fix warnings (From HEAD, original patch by Ben).
[openssl.git] / crypto / rand / rand_egd.c
index abc3ac27d552c51a270fb60eed5601bd326e5b4e..d53b916ebee87c7ae77700c2fb5464920ae12cc1 100644 (file)
@@ -56,6 +56,7 @@
 
 #include <openssl/e_os2.h>
 #include <openssl/rand.h>
+#include <openssl/buffer.h>
 
 /*
  * Query the EGD <URL: http://www.lothar.com/tech/crypto/>.
@@ -94,7 +95,7 @@
  *   RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255.
  */
 
-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(__DJGPP__)
+#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) || defined(OPENSSL_SYS_BEOS)
 int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
        {
        return(-1);
@@ -114,7 +115,7 @@ int RAND_egd_bytes(const char *path,int bytes)
 #include <sys/types.h>
 #include <sys/socket.h>
 #ifndef NO_SYS_UN_H
-# ifdef OPENSSL_SYS_VSWORKS
+# ifdef OPENSSL_SYS_VXWORKS
 #   include <streams/un.h>
 # else
 #   include <sys/un.h>
@@ -143,9 +144,9 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
 
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_UNIX;
-       if (strlen(path) > sizeof(addr.sun_path))
+       if (strlen(path) >= sizeof(addr.sun_path))
                return (-1);
-       strcpy(addr.sun_path,path);
+       BUF_strlcpy(addr.sun_path,path,sizeof addr.sun_path);
        len = offsetof(struct sockaddr_un, sun_path) + strlen(path);
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
        if (fd == -1) return (-1);
@@ -215,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
                    {
@@ -245,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
                    {