define USE_SOCKETS so sys/param.h gets included (and thusly, MAXHOSTNAMELEN
[openssl.git] / ssl / ssltest.c
index c84c643c2e23e051311d06fdda02332445a59c3f..978516f1b7b9bbdf7d04d31f52c29fac46d02e9a 100644 (file)
 #include <string.h>
 #include <time.h>
 
+#define USE_SOCKETS
 #include "e_os.h"
 
 #include <openssl/bio.h>
 #ifdef OPENSSL_SYS_VMS
 #  define TEST_SERVER_CERT "SYS$DISK:[-.APPS]SERVER.PEM"
 #  define TEST_CLIENT_CERT "SYS$DISK:[-.APPS]CLIENT.PEM"
+#elif defined(OPENSSL_SYS_WINCE)
+#  define TEST_SERVER_CERT "\\OpenSSL\\server.pem"
+#  define TEST_CLIENT_CERT "\\OpenSSL\\client.pem"
 #else
 #  define TEST_SERVER_CERT "../apps/server.pem"
 #  define TEST_CLIENT_CERT "../apps/client.pem"
@@ -382,7 +386,9 @@ int main(int argc, char *argv[])
        verbose = 0;
        debug = 0;
        cipher = 0;
-       
+
+       bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 
+
        CRYPTO_set_locking_callback(lock_dbg_cb);
 
        /* enable memory leak checking unless explicitly disabled */
@@ -400,7 +406,6 @@ int main(int argc, char *argv[])
 
        RAND_seed(rnd_seed, sizeof rnd_seed);
 
-       bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
        bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
 
        argc--;
@@ -423,7 +428,7 @@ int main(int argc, char *argv[])
 #ifndef OPENSSL_NO_DH
                        dhe1024=1;
 #else
-                       fprintf(stderr,"ignoring -dhe1024, since I'm compiled without DH\n";
+                       fprintf(stderr,"ignoring -dhe1024, since I'm compiled without DH\n");
 #endif
                        }
                else if (strcmp(*argv,"-dhe1024dsa") == 0)
@@ -431,7 +436,7 @@ int main(int argc, char *argv[])
 #ifndef OPENSSL_NO_DH
                        dhe1024dsa=1;
 #else
-                       fprintf(stderr,"ignoring -dhe1024, since I'm compiled without DH\n";
+                       fprintf(stderr,"ignoring -dhe1024, since I'm compiled without DH\n");
 #endif
                        }
                else if (strcmp(*argv,"-no_dhe") == 0)
@@ -530,7 +535,7 @@ int main(int argc, char *argv[])
 #ifndef OPENSSL_NO_ECDH                
                        named_curve = *(++argv);
 #else
-                       fprintf(stderr,"ignoring -named_curve, since I'm compiled without ECDH\n"
+                       fprintf(stderr,"ignoring -named_curve, since I'm compiled without ECDH\n");
                        ++argv;
 #endif
                        }
@@ -560,7 +565,7 @@ bad:
                        "the test anyway (and\n-d to see what happens), "
                        "or add one of -ssl2, -ssl3, -tls1, -reuse\n"
                        "to avoid protocol mismatch.\n");
-               exit(1);
+               EXIT(1);
                }
 
        if (print_time)
@@ -754,10 +759,16 @@ bad:
 #ifndef OPENSSL_NO_KRB5
        if (c_ssl  &&  c_ssl->kssl_ctx)
                 {
-                char   localhost[257];
+                char   localhost[MAXHOSTNAMELEN+2];
 
-               if (gethostname(localhost, 256) == 0)
+               if (gethostname(localhost, sizeof localhost-1) == 0)
                         {
+                       localhost[sizeof localhost-1]='\0';
+                       if(strlen(localhost) == sizeof localhost-1)
+                               {
+                               BIO_printf(bio_err,"localhost name too long\n");
+                               goto end;
+                               }
                        kssl_ctx_setstring(c_ssl->kssl_ctx, KSSL_SERVER,
                                 localhost);
                        }
@@ -903,6 +914,8 @@ int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count,
                        int i, r;
                        clock_t c_clock = clock();
 
+                       memset(cbuf, 0, sizeof(cbuf));
+
                        if (debug)
                                if (SSL_in_init(c_ssl))
                                        printf("client waiting in SSL_connect - %s\n",
@@ -987,6 +1000,8 @@ int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count,
                        int i, r;
                        clock_t s_clock = clock();
 
+                       memset(sbuf, 0, sizeof(sbuf));
+
                        if (debug)
                                if (SSL_in_init(s_ssl))
                                        printf("server waiting in SSL_accept - %s\n",
@@ -1230,6 +1245,9 @@ int doit(SSL *s_ssl, SSL *c_ssl, long count)
        int c_write,s_write;
        int do_server=0,do_client=0;
 
+       memset(cbuf,0,sizeof(cbuf));
+       memset(sbuf,0,sizeof(sbuf));
+
        c_to_s=BIO_new(BIO_s_mem());
        s_to_c=BIO_new(BIO_s_mem());
        if ((s_to_c == NULL) || (c_to_s == NULL))
@@ -1511,7 +1529,8 @@ static int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
        {
        char *s,buf[256];
 
-       s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),buf,256);
+       s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),buf,
+                           sizeof buf);
        if (s != NULL)
                {
                if (ok)