Free malloc data on encoding errors.
[openssl.git] / apps / s_server.c
index 8199b888f89485591dc71402318da197082ee24c..da725e7a4da87509b9edad762d83cb7ab90028b1 100644 (file)
@@ -1378,7 +1378,7 @@ int s_server_main(int argc, char *argv[])
             session_id_prefix = opt_arg();
             break;
         case OPT_ENGINE:
-            engine_id = opt_arg();
+            e = setup_engine(opt_arg(), 1);
             break;
         case OPT_RAND:
             inrand = opt_arg();
@@ -1449,10 +1449,6 @@ int s_server_main(int argc, char *argv[])
     }
 #endif
 
-#ifndef OPENSSL_NO_ENGINE
-    e = setup_engine(engine_id, 1);
-#endif
-
     if (!app_passwd(passarg, dpassarg, &pass, &dpass)) {
         BIO_printf(bio_err, "Error getting password\n");
         goto end;
@@ -2727,7 +2723,22 @@ static int www_body(char *hostname, int s, int stype, unsigned char *context)
 /*                      BIO_puts(io,SSLeay_version(SSLEAY_VERSION));*/
             BIO_puts(io, "\n");
             for (i = 0; i < local_argc; i++) {
-                BIO_puts(io, local_argv[i]);
+                const char *myp;
+                for (myp = local_argv[i]; *myp; myp++)
+                    switch (*myp) {
+                    case '<':
+                        BIO_puts(io, "&lt;");
+                        break;
+                    case '>':
+                        BIO_puts(io, "&gt;");
+                        break;
+                    case '&':
+                        BIO_puts(io, "&amp;");
+                        break;
+                    default:
+                        BIO_write(io, myp, 1);
+                        break;
+                    }
                 BIO_write(io, " ", 1);
             }
             BIO_puts(io, "\n");
@@ -3158,6 +3169,7 @@ static int add_session(SSL *ssl, SSL_SESSION *session)
     sess->derlen = i2d_SSL_SESSION(session, NULL);
     if (sess->derlen < 0) {
         BIO_printf(bio_err, "Error encoding session\n");
+        OPENSSL_free(sess);
         return 0;
     }
 
@@ -3165,10 +3177,8 @@ static int add_session(SSL *ssl, SSL_SESSION *session)
     sess->der = OPENSSL_malloc(sess->derlen);
     if (!sess->id || !sess->der) {
         BIO_printf(bio_err, "Out of memory adding to external cache\n");
-        if (sess->id)
-            OPENSSL_free(sess->id);
-        if (sess->der)
-            OPENSSL_free(sess->der);
+        OPENSSL_free(sess->id);
+        OPENSSL_free(sess->der);
         OPENSSL_free(sess);
         return 0;
     }
@@ -3176,7 +3186,10 @@ static int add_session(SSL *ssl, SSL_SESSION *session)
 
     /* Assume it still works. */
     if (i2d_SSL_SESSION(session, &p) != sess->derlen) {
-        BIO_printf(bio_err, "Error encoding session\n");
+        BIO_printf(bio_err, "Re-encoding session strangeness\n");
+        OPENSSL_free(sess->id);
+        OPENSSL_free(sess->der);
+        OPENSSL_free(sess);
         return 0;
     }