Fix for memcpy() and strcmp() being undefined.
[openssl.git] / apps / s_cb.c
index 1d026b6514ad531c5c11885a4571739c03f650be..4979edfe65e03273862b9de9a67a9aaf67e8cda2 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <string.h> /* for memcpy() and strcmp() */
 #define USE_SOCKETS
 #include "apps.h"
 #undef USE_SOCKETS
@@ -439,11 +440,7 @@ int ssl_print_curves(BIO *out, SSL *s, int noshared)
     ncurves = SSL_get1_curves(s, NULL);
     if (ncurves <= 0)
         return 1;
-    curves = OPENSSL_malloc(ncurves * sizeof(int));
-    if (!curves) {
-        BIO_printf(out, "Out of memory\n");
-        return 0;
-    }
+    curves = app_malloc(ncurves * sizeof(int), "curves to print");
     SSL_get1_curves(s, curves);
 
     BIO_puts(out, "Supported Elliptic Curves: ");
@@ -955,12 +952,7 @@ int generate_cookie_callback(SSL *ssl, unsigned char *cookie,
         OPENSSL_assert(0);
         break;
     }
-    buffer = OPENSSL_malloc(length);
-
-    if (buffer == NULL) {
-        BIO_printf(bio_err, "out of memory\n");
-        return 0;
-    }
+    buffer = app_malloc(length, "cookie generate buffer");
 
     switch (peer.sa.sa_family) {
     case AF_INET:
@@ -1028,12 +1020,7 @@ int verify_cookie_callback(SSL *ssl, unsigned char *cookie,
         OPENSSL_assert(0);
         break;
     }
-    buffer = OPENSSL_malloc(length);
-
-    if (buffer == NULL) {
-        BIO_printf(bio_err, "out of memory\n");
-        return 0;
-    }
+    buffer = app_malloc(length, "cookie verify buffer");
 
     switch (peer.sa.sa_family) {
     case AF_INET:
@@ -1187,10 +1174,8 @@ void ssl_ctx_set_excert(SSL_CTX *ctx, SSL_EXCERT *exc)
 
 static int ssl_excert_prepend(SSL_EXCERT **pexc)
 {
-    SSL_EXCERT *exc;
-    exc = OPENSSL_malloc(sizeof(SSL_EXCERT));
-    if (!exc)
-        return 0;
+    SSL_EXCERT *exc = app_malloc(sizeof(*exc), "prepend cert");
+
     exc->certfile = NULL;
     exc->keyfile = NULL;
     exc->chainfile = NULL;
@@ -1218,6 +1203,9 @@ static int ssl_excert_prepend(SSL_EXCERT **pexc)
 void ssl_excert_free(SSL_EXCERT *exc)
 {
     SSL_EXCERT *curr;
+
+    if (!exc)
+        return;
     while (exc) {
         X509_free(exc->cert);
         EVP_PKEY_free(exc->key);
@@ -1327,8 +1315,7 @@ int args_excert(int opt, SSL_EXCERT **pexc)
 
  err:
     ERR_print_errors(bio_err);
-    if (exc)
-        ssl_excert_free(exc);
+    ssl_excert_free(exc);
     *pexc = NULL;
     return 0;
 }
@@ -1406,10 +1393,10 @@ int config_ctx(SSL_CONF_CTX *cctx, STACK_OF(OPENSSL_STRING) *str,
         const char *flag = sk_OPENSSL_STRING_value(str, i);
         const char *arg = sk_OPENSSL_STRING_value(str, i + 1);
         /* If no_ecdhe or named curve already specified don't need a default. */
-        if (!no_ecdhe && !strcmp(flag, "-named_curve"))
+        if (!no_ecdhe && strcmp(flag, "-named_curve") == 0)
             no_ecdhe = 1;
 #ifndef OPENSSL_NO_JPAKE
-        if (!no_jpake && !strcmp(flag, "-cipher")) {
+        if (!no_jpake && (strcmp(flag, "-cipher") == 0)) {
             BIO_puts(bio_err, "JPAKE sets cipher to PSK\n");
             return 0;
         }