Security fixes brought forward from 0.9.7.
[openssl.git] / apps / s_socket.c
index f60d92948431bb96d983ad66b31abcef1fe14e3c..01a980c96d2345f7609d0d91e7bebc4f56df3c91 100644 (file)
 #include <errno.h>
 #include <signal.h>
 
-#define USE_SOCKETS
-#define NON_MAIN
-#include "apps.h"
-#undef USE_SOCKETS
-#undef NON_MAIN
-#include "s_apps.h"
-#include <openssl/ssl.h>
+#include <openssl/e_os2.h>
 
 /* With IPv6, it looks like Digital has mixed up the proper order of
    recursive header file inclusion, resulting in the compiler complaining
 typedef unsigned int u_int;
 #endif
 
+#define USE_SOCKETS
+#define NON_MAIN
+#include "apps.h"
+#undef USE_SOCKETS
+#undef NON_MAIN
+#include "s_apps.h"
+#include <openssl/ssl.h>
+
 static struct hostent *GetHostByName(char *name);
 #ifdef OPENSSL_SYS_WINDOWS
 static void sock_cleanup(void);
@@ -527,9 +529,12 @@ static struct hostent *GetHostByName(char *name)
                ret=gethostbyname(name);
                if (ret == NULL) return(NULL);
                /* else add to cache */
-               strncpy(ghbn_cache[lowi].name,name,128);
-               memcpy((char *)&(ghbn_cache[lowi].ent),ret,sizeof(struct hostent));
-               ghbn_cache[lowi].order=ghbn_miss+ghbn_hits;
+               if(strlen(name) < sizeof ghbn_cache[0].name)
+                       {
+                       strcpy(ghbn_cache[lowi].name,name);
+                       memcpy((char *)&(ghbn_cache[lowi].ent),ret,sizeof(struct hostent));
+                       ghbn_cache[lowi].order=ghbn_miss+ghbn_hits;
+                       }
                return(ret);
                }
        else