]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Make sure options->ciphername and options->authname are always defined
authorSteffan Karger <steffan@karger.me>
Wed, 28 Sep 2016 10:40:51 +0000 (12:40 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 28 Sep 2016 10:40:51 +0000 (12:40 +0200)
The NCP code does a strcmp(options->ciphername, ...) without first checking
whether options->ciphername is NULL.  This could cause a crash when using
"--cipher none".  This patch fixes that problem by ensuring that
options->ciphername (and options->authname) are never NULL.  Ensuring that
options->ciphername is never null prevents us from having to write null
checks everywhere.

Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1475055231-1778-1-git-send-email-steffan@karger.me>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg12576.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/crypto.c
src/openvpn/init.c
src/openvpn/options.c

index 6f578419adba3530b8e1ee3482a989cde16ce088..4ea0082c423b92aa14c2397167a69fe5b29cc236 100644 (file)
@@ -759,8 +759,11 @@ init_key_type (struct key_type *kt, const char *ciphername,
 {
   bool aead_cipher = false;
 
+  ASSERT(ciphername);
+  ASSERT(authname);
+
   CLEAR (*kt);
-  if (ciphername)
+  if (strcmp (ciphername, "none") != 0)
     {
       kt->cipher = cipher_kt_get (translate_cipher_name_from_openvpn(ciphername));
       kt->cipher_length = cipher_kt_key_size (kt->cipher);
@@ -785,7 +788,7 @@ init_key_type (struct key_type *kt, const char *ciphername,
       if (warn)
        msg (M_WARN, "******* WARNING *******: null cipher specified, no encryption will be used");
     }
-  if (authname)
+  if (strcmp (authname, "none") != 0)
     {
       if (!aead_cipher) { /* Ignore auth for AEAD ciphers */
        kt->digest = md_kt_get (authname);
index 45ce025ee52e9b251073fdbab04694886af3e74e..e3206b05e9bc730a49c859b134d0da3f5eb8fd5f 100644 (file)
@@ -2266,7 +2266,7 @@ do_init_crypto_tls_c1 (struct context *c)
 
          /* Initialize key_type for tls-auth with auth only */
          CLEAR (c->c1.ks.tls_auth_key_type);
-         if (options->authname)
+         if (!streq (options->authname, "none"))
            {
              c->c1.ks.tls_auth_key_type.digest = md_kt_get (options->authname);
              c->c1.ks.tls_auth_key_type.hmac_length =
index 4b7203d9ba3bbed5a941f3fb817e7e0623146b9f..9f6099c20e0262b8de8975d57efbd4b9aeecf635 100644 (file)
@@ -6659,19 +6659,11 @@ add_option (struct options *options,
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
       options->authname = p[1];
-      if (streq (options->authname, "none"))
-       {
-         options->authname = NULL;
-       }
     }
   else if (streq (p[0], "cipher") && p[1] && !p[2])
     {
       VERIFY_PERMISSION (OPT_P_NCP);
       options->ciphername = p[1];
-      if (streq (options->ciphername, "none"))
-       {
-         options->ciphername = NULL;
-       }
     }
   else if (streq (p[0], "ncp-ciphers") && p[1] && !p[2])
     {