[openssl] master update

Richard Levitte levitte at openssl.org
Tue Mar 5 07:54:24 UTC 2019


The branch master has been updated
       via  ce506d27ab5e7d17dfe3fe649768a0d19b6c86ee (commit)
       via  9b542d72d2e7d4893a11b2e87628d9ac8637b954 (commit)
      from  469ce8ff48ef06b2e508d0c06a42ec86379b0032 (commit)


- Log -----------------------------------------------------------------
commit ce506d27ab5e7d17dfe3fe649768a0d19b6c86ee
Author: Richard Levitte <levitte at openssl.org>
Date:   Sun Mar 3 10:27:10 2019 +0100

    testutil: ensure good treatment of argv on non-Unix platforms
    
    From a Unix point of view, some other platform families have certain
    quirks.  Windows command prompt doesn't expand globs into actual file
    names, so we must do this.  VMS has some oddity with argv pointer size
    that can cause crashes if you're not careful (by copying it to a less
    surprising pointer size array).
    
    The fixups already exist and are used in the apps/ code.  However, the
    testutil code started using the opt routines from apps/ without
    including the non-Unix fixups.  This change fixes that.
    
    For VMS' sake, libtestutil gets an app_malloc() shim, to avoid sucking
    in all of apps/apps.c.
    
    Reviewed-by: Paul Dale <paul.dale at oracle.com>
    (Merged from https://github.com/openssl/openssl/pull/8381)

commit 9b542d72d2e7d4893a11b2e87628d9ac8637b954
Author: Richard Levitte <levitte at openssl.org>
Date:   Sun Mar 3 10:20:37 2019 +0100

    VMS: move copy_argc to its own module and make it an aux source
    
    copy_argv was never initialization code.
    
    Make it self-cleaning too.
    
    Reviewed-by: Paul Dale <paul.dale at oracle.com>
    (Merged from https://github.com/openssl/openssl/pull/8381)

-----------------------------------------------------------------------

Summary of changes:
 Configurations/10-main.conf          |  2 +-
 apps/include/apps.h                  | 13 +------
 apps/include/platform.h              | 32 +++++++++++++++++
 apps/openssl.c                       |  4 +--
 apps/vms_decc_argv.c                 | 67 ++++++++++++++++++++++++++++++++++++
 apps/vms_decc_init.c                 | 38 --------------------
 test/build.info                      |  5 ++-
 test/testutil/{init.c => apps_mem.c} | 12 ++++---
 test/testutil/driver.c               | 12 +++++++
 9 files changed, 126 insertions(+), 59 deletions(-)
 create mode 100644 apps/include/platform.h
 create mode 100644 apps/vms_decc_argv.c
 copy test/testutil/{init.c => apps_mem.c} (53%)

diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf
index 8b758a0..0e3afd3 100644
--- a/Configurations/10-main.conf
+++ b/Configurations/10-main.conf
@@ -1725,7 +1725,7 @@ my %targets = (
 
         disable          => add('pinshared'),
 
-        apps_aux_src     => "vms_term_sock.c",
+        apps_aux_src     => "vms_term_sock.c vms_decc_argv.c",
         apps_init_src    => "vms_decc_init.c",
     },
 
diff --git a/apps/include/apps.h b/apps/include/apps.h
index da8eae2..59e3e92 100644
--- a/apps/include/apps.h
+++ b/apps/include/apps.h
@@ -32,6 +32,7 @@
 # include "apps_ui.h"
 # include "opt.h"
 # include "fmt.h"
+# include "platform.h"
 
 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
 #  define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
@@ -97,18 +98,6 @@ typedef struct args_st {
     char **argv;
 } ARGS;
 
-/*
- * VMS C only for now, implemented in vms_decc_init.c
- * If other C compilers forget to terminate argv with NULL, this function
- * can be re-used.
- */
-char **copy_argv(int *argc, char *argv[]);
-/*
- * Win32-specific argv initialization that splits OS-supplied UNICODE
- * command line string to array of UTF8-encoded strings.
- */
-void win32_utf8argv(int *argc, char **argv[]);
-
 /* We need both wrap and the "real" function because libcrypto uses both. */
 int wrap_password_callback(char *buf, int bufsiz, int verify, void *cb_data);
 
diff --git a/apps/include/platform.h b/apps/include/platform.h
new file mode 100644
index 0000000..49276b6
--- /dev/null
+++ b/apps/include/platform.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#ifndef HEADER_PLATFORM_H
+# define HEADER_PLATFORM_H
+
+# include <openssl/e_os2.h>
+
+# if defined(OPENSSL_SYS_VMS) && defined(__DECC)
+/*
+ * VMS C only for now, implemented in vms_decc_init.c
+ * If other C compilers forget to terminate argv with NULL, this function
+ * can be re-used.
+ */
+char **copy_argv(int *argc, char *argv[]);
+# endif
+
+# ifdef _WIN32
+/*
+ * Win32-specific argv initialization that splits OS-supplied UNICODE
+ * command line string to array of UTF8-encoded strings.
+ */
+void win32_utf8argv(int *argc, char **argv[]);
+# endif
+
+#endif
diff --git a/apps/openssl.c b/apps/openssl.c
index 3747b1a..6b63b36 100644
--- a/apps/openssl.c
+++ b/apps/openssl.c
@@ -121,7 +121,6 @@ int main(int argc, char *argv[])
 {
     FUNCTION f, *fp;
     LHASH_OF(FUNCTION) *prog = NULL;
-    char **copied_argv = NULL;
     char *p, *pname;
     char buf[1024];
     const char *prompt;
@@ -138,7 +137,7 @@ int main(int argc, char *argv[])
     bio_err = dup_bio_err(FORMAT_TEXT);
 
 #if defined(OPENSSL_SYS_VMS) && defined(__DECC)
-    copied_argv = argv = copy_argv(&argc, argv);
+    argv = copy_argv(&argc, argv);
 #elif defined(_WIN32)
     /*
      * Replace argv[] with UTF-8 encoded strings.
@@ -252,7 +251,6 @@ int main(int argc, char *argv[])
     }
     ret = 1;
  end:
-    OPENSSL_free(copied_argv);
     OPENSSL_free(default_config_file);
     lh_FUNCTION_free(prog);
     OPENSSL_free(arg.argv);
diff --git a/apps/vms_decc_argv.c b/apps/vms_decc_argv.c
new file mode 100644
index 0000000..932b51a
--- /dev/null
+++ b/apps/vms_decc_argv.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <stdlib.h>
+#include <openssl/crypto.h>
+#include "platform.h"            /* for copy_argv() */
+#include "apps.h"                /* for app_malloc() */
+
+char **newargv = NULL;
+
+static void cleanup_argv(void)
+{
+    OPENSSL_free(newargv);
+    newargv = NULL;
+}
+
+char **copy_argv(int *argc, char *argv[])
+{
+    /*-
+     * The note below is for historical purpose.  On VMS now we always
+     * copy argv "safely."
+     *
+     * 2011-03-22 SMS.
+     * If we have 32-bit pointers everywhere, then we're safe, and
+     * we bypass this mess, as on non-VMS systems.
+     * Problem 1: Compaq/HP C before V7.3 always used 32-bit
+     * pointers for argv[].
+     * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers
+     * everywhere else, we always allocate and use a 64-bit
+     * duplicate of argv[].
+     * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed
+     * to NULL-terminate a 64-bit argv[].  (As this was written, the
+     * compiler ECO was available only on IA64.)
+     * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a
+     * 64-bit argv[argc] for NULL, and, if necessary, use a
+     * (properly) NULL-terminated (64-bit) duplicate of argv[].
+     * The same code is used in either case to duplicate argv[].
+     * Some of these decisions could be handled in preprocessing,
+     * but the code tends to get even uglier, and the penalty for
+     * deciding at compile- or run-time is tiny.
+     */
+
+    int i, count = *argc;
+    char **p = newargv;
+
+    cleanup_argv();
+
+    newargv = app_malloc(sizeof(*newargv) * (count + 1), "argv copy");
+    if (newargv == NULL)
+        return NULL;
+
+    /* Register automatic cleanup on first use */
+    if (p == NULL)
+        OPENSSL_atexit(cleanup_argv);
+
+    for (i = 0; i < count; i++)
+        newargv[i] = argv[i];
+    newargv[i] = NULL;
+    *argc = i;
+    return newargv;
+}
diff --git a/apps/vms_decc_init.c b/apps/vms_decc_init.c
index c26442e..21481e2 100644
--- a/apps/vms_decc_init.c
+++ b/apps/vms_decc_init.c
@@ -25,8 +25,6 @@
 # include <stdlib.h>
 # include <unixlib.h>
 
-# include "apps.h"
-
 /* Global storage. */
 
 /* Flag to sense if decc_init() was called. */
@@ -63,42 +61,6 @@ decc_feat_t decc_feat_array[] = {
 };
 
 
-char **copy_argv(int *argc, char *argv[])
-{
-    /*-
-     * The note below is for historical purpose.  On VMS now we always
-     * copy argv "safely."
-     *
-     * 2011-03-22 SMS.
-     * If we have 32-bit pointers everywhere, then we're safe, and
-     * we bypass this mess, as on non-VMS systems.
-     * Problem 1: Compaq/HP C before V7.3 always used 32-bit
-     * pointers for argv[].
-     * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers
-     * everywhere else, we always allocate and use a 64-bit
-     * duplicate of argv[].
-     * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed
-     * to NULL-terminate a 64-bit argv[].  (As this was written, the
-     * compiler ECO was available only on IA64.)
-     * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a
-     * 64-bit argv[argc] for NULL, and, if necessary, use a
-     * (properly) NULL-terminated (64-bit) duplicate of argv[].
-     * The same code is used in either case to duplicate argv[].
-     * Some of these decisions could be handled in preprocessing,
-     * but the code tends to get even uglier, and the penalty for
-     * deciding at compile- or run-time is tiny.
-     */
-
-    int i, count = *argc;
-    char **newargv = app_malloc(sizeof(*newargv) * (count + 1), "argv copy");
-
-    for (i = 0; i < count; i++)
-        newargv[i] = argv[i];
-    newargv[i] = NULL;
-    *argc = i;
-    return newargv;
-}
-
 /* LIB$INITIALIZE initialization function. */
 
 static void decc_init(void)
diff --git a/test/build.info b/test/build.info
index 1a47463..372f9be 100644
--- a/test/build.info
+++ b/test/build.info
@@ -6,6 +6,8 @@ SUBDIRS=ossl_shim
          my ($base, $files) = @_;
          return join(" ", map { "$base/$_" } split(/\s+/, $files));
      }
+     our $apps_aux_src =
+         join(' ', map { "../apps/$_" } split(/\s+/, $target{apps_aux_src}));
      ""
 -}
 IF[{- !$disabled{tests} -}]
@@ -14,7 +16,8 @@ IF[{- !$disabled{tests} -}]
           testutil/driver.c testutil/tests.c testutil/cb.c testutil/stanza.c \
           testutil/format_output.c testutil/tap_bio.c \
           testutil/test_cleanup.c testutil/main.c testutil/init.c \
-          testutil/options.c testutil/test_options.c ../apps/opt.c
+          testutil/options.c testutil/test_options.c \
+          testutil/apps_mem.c ../apps/opt.c {- $apps_aux_src; -}
   INCLUDE[libtestutil.a]=../include ../apps/include ..
   DEPEND[libtestutil.a]=../libcrypto
 
diff --git a/test/testutil/init.c b/test/testutil/apps_mem.c
similarity index 53%
copy from test/testutil/init.c
copy to test/testutil/apps_mem.c
index 4415902..fa60bc6 100644
--- a/test/testutil/init.c
+++ b/test/testutil/apps_mem.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -7,9 +7,13 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include "../testutil.h"
+#include "apps.h"
 
-int global_init(void)
+/* shim that avoids sucking in too much from apps/apps.c */
+
+void* app_malloc(int sz, const char *what)
 {
-    return 1;
+    void *vp = OPENSSL_malloc(sz);
+
+    return vp;
 }
diff --git a/test/testutil/driver.c b/test/testutil/driver.c
index df62625..10d74e2 100644
--- a/test/testutil/driver.c
+++ b/test/testutil/driver.c
@@ -17,6 +17,8 @@
 #include "internal/nelem.h"
 #include <openssl/bio.h>
 
+#include "platform.h"            /* From libapps */
+
 #ifdef _WIN32
 # define strdup _strdup
 #endif
@@ -132,6 +134,16 @@ int setup_test_framework(int argc, char *argv[])
         CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
     }
 #endif
+
+#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
+    argv = copy_argv(&argc, argv);
+#elif defined(_WIN32)
+    /*
+     * Replace argv[] with UTF-8 encoded strings.
+     */
+    win32_utf8argv(&argc, &argv);
+#endif
+
     if (!opt_init(argc, argv, test_get_options()))
         return 0;
     return 1;


More information about the openssl-commits mailing list