[openssl-commits] [openssl] master update

Richard Levitte levitte at openssl.org
Wed Apr 25 09:44:46 UTC 2018


The branch master has been updated
       via  4522e130c87c341342c640bba970f4b89755f1cb (commit)
       via  c36e9093914aab4bfc42af1db35558a9272607b5 (commit)
       via  96de2e590bad00575baa7c2c6be5767b43aa017c (commit)
       via  b47b6650164711de449a7738112a3efb733213e2 (commit)
       via  b9a354d08810e95c03dec1f796fdd4069a4001e7 (commit)
       via  39e32be1ccc527036e0a52c3cf64a40faf28ab9d (commit)
      from  22f0c72b928604cc42c16bf59b9d31f92e4c4be9 (commit)


- Log -----------------------------------------------------------------
commit 4522e130c87c341342c640bba970f4b89755f1cb
Author: Richard Levitte <levitte at openssl.org>
Date:   Tue Apr 24 14:31:32 2018 +0200

    apps/opt.c: Remove the access checks of input and output files
    
    open() will take care of the checks anyway
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6033)

commit c36e9093914aab4bfc42af1db35558a9272607b5
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 20 12:27:14 2018 +0200

    Better check of return values from app_isdir and app_access
    
    [extended tests]
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6033)

commit 96de2e590bad00575baa7c2c6be5767b43aa017c
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 20 12:22:45 2018 +0200

    Revert "Check directory is able to create files for various -out option"
    
    This reverts commit 555c94a0db9661428da0a45cb32b9f002324eefd.
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6033)

commit b47b6650164711de449a7738112a3efb733213e2
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 20 12:22:36 2018 +0200

    Revert "Add VMS version of app_dirname()"
    
    This reverts commit 215a6730f1eaf53b01a4eb10d75bd09fd74f70cc.
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6033)

commit b9a354d08810e95c03dec1f796fdd4069a4001e7
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 20 12:22:27 2018 +0200

    Revert "Check on VMS as well"
    
    This reverts commit f6d765988f37c43edb1056ab83165f2569182e9d.
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6033)

commit 39e32be1ccc527036e0a52c3cf64a40faf28ab9d
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 20 08:36:18 2018 +0200

    test/recipes/15-test_out_option.t: refine tests
    
    Test writing to the null device.  This should be successful.
    
    Also, refactor so the planned number of tests is calculated.
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6033)

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

Summary of changes:
 apps/apps.c                       | 116 --------------------------------------
 apps/apps.h                       |   1 -
 apps/opt.c                        |  47 +--------------
 test/recipes/15-test_out_option.t |  71 ++++++++++++-----------
 4 files changed, 40 insertions(+), 195 deletions(-)

diff --git a/apps/apps.c b/apps/apps.c
index 6ae8523..b35ea56 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -25,12 +25,6 @@
 #endif
 #include <ctype.h>
 #include <errno.h>
-#ifdef __VMS
-# include <descrip.h>
-# include <iledef.h>
-# include <fscndef.h>
-# include <starlet.h>
-#endif
 #include <openssl/err.h>
 #include <openssl/x509.h>
 #include <openssl/x509v3.h>
@@ -2370,116 +2364,6 @@ int app_isdir(const char *name)
 }
 #endif
 
-/* app_dirname section */
-
-/*
- * This exactly follows what POSIX's
- * dirname does, but is implemented
- * in a more platform independent way.
- *
- * path        dirname
- * /usr/lib    /usr
- * /usr/       /
- * usr         .
- * /           /
- * .           .
- * ..          .
- * ""          .
- *
- * Note: this function also keeps the
- * possibility of modifying the 'path'
- * string same as POSIX dirname.
- */
-static char *posix_dirname(char *path)
-{
-    size_t l;
-    char *ret = ".";
-
-    l = strlen(path);
-    if (l == 0)
-        goto out;
-    if (strcmp(path, ".") == 0)
-        goto out;
-    if (strcmp(path, "..") == 0)
-        goto out;
-    if (strcmp(path, "/") == 0) {
-        ret = "/";
-        goto out;
-    }
-    if (path[l - 1] == '/') {
-        /* /usr/ */
-        path[l - 1] = '\0';
-    }
-    if ((ret = strrchr(path, '/')) == NULL) {
-        /* usr */
-        ret = ".";
-    } else if (ret == path) {
-        /* /usr */
-        *++ret = '\0';
-        ret = path;
-    } else {
-        /* /usr/lib */
-        *ret = '\0';
-        ret = path;
-    }
- out:
-    return ret;
-}
-
-/*
- * TODO: implement app_dirname for Windows.
- */
-#if !defined(_WIN32)
-char *app_dirname(char *path)
-{
-    return posix_dirname(path);
-}
-#elif defined(__VMS)
-/*
- * sys$filescan fills the given item list with pointers into the original
- * path string, so all we need to do is to find the file name and simply
- * put a NUL byte wherever the FSCN$_NAME pointer points.  If there is no
- * file name part and the path string isn't the empty string, we know for
- * a fact that the whole string is a directory spec and return it as is.
- * Otherwise or if that pointer is the starting address of the original
- * path string, we know to return "sys$disk:[]", which corresponds to the
- * Unixly ".".
- *
- * If sys$filescan returns an error status, we know that this is not
- * parsable as a VMS file spec, and then use the fallback, in case we
- * have a Unix type path.
- */
-char *app_dirname(char *path)
-{
-    char *ret = "sys$disk:[]";
-    struct dsc$descriptor_s dsc_path = { 0 };
-    ile2 itemlist[] = {
-        {0, FSCN$_NAME, 0},
-        {0, 0, 0}
-    };
-    int fields;
-    int status;
-
-    dsc_path.dsc$a_pointer = path;
-    dsc_path.dsc$w_length = strlen(path);
-    status = sys$filescan(&dsc_path, itemlist, &fields, 0, 0);
-
-    if (!(status & 1))
-        return posix_dirname(path);
-
-    if ((fields & (1 << FSCN$_NAME)) == 0) {
-        if (dsc_path.dsc$w_length != 0)
-            ret = path;
-    } else if (itemlist[0].ile2$ps_bufaddr != path) {
-        if (itemlist[0].ile2$ps_bufaddr != path) {
-            *itemlist[0].ile2$ps_bufaddr = '\0';
-            ret = path;
-        }
-    }
-    return ret;
-}
-#endif
-
 /* raw_read|write section */
 #if defined(__VMS)
 # include "vms_term_sock.h"
diff --git a/apps/apps.h b/apps/apps.h
index 4d4aae7..b45a31a 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -611,7 +611,6 @@ void store_setup_crl_download(X509_STORE *st);
 
 int app_isdir(const char *);
 int app_access(const char *, int flag);
-char *app_dirname(char *path);
 int fileno_stdin(void);
 int fileno_stdout(void);
 int raw_read_stdin(void *, int);
diff --git a/apps/opt.c b/apps/opt.c
index 9025636..cc14184 100644
--- a/apps/opt.c
+++ b/apps/opt.c
@@ -613,17 +613,13 @@ int opt_verify(int opt, X509_VERIFY_PARAM *vpm)
  */
 int opt_next(void)
 {
-    char *p, *estr;
+    char *p;
     const OPTIONS *o;
     int ival;
     long lval;
     unsigned long ulval;
     ossl_intmax_t imval;
     ossl_uintmax_t umval;
-#if !defined(_WIN32)
-    char *c;
-    int oerrno;
-#endif
 
     /* Look at current arg; at end of the list? */
     arg = NULL;
@@ -686,47 +682,10 @@ int opt_next(void)
             return -1;
         case '<':
             /* Input file. */
-            if (strcmp(arg, "-") == 0 || app_access(arg, R_OK) == 0)
-                break;
-            BIO_printf(bio_err,
-                       "%s: Cannot open input file %s, %s\n",
-                       prog, arg, strerror(errno));
-            return -1;
+            break;
         case '>':
             /* Output file. */
-#if !defined(_WIN32)
-            c = OPENSSL_strdup(arg);
-            if (c == NULL) {
-                BIO_printf(bio_err,
-                           "%s: Memory allocation failure\n", prog);
-                return -1;
-            }
-            oerrno = errno;
-            errno = 0;
-            if (strcmp(arg, "-") == 0
-                || (app_access(app_dirname(c), W_OK) == 0
-                    && app_isdir(arg) <= 0
-                    && (app_access(arg, W_OK) == 0 || errno == ENOENT))) {
-                OPENSSL_free(c);
-                break;
-            }
-            OPENSSL_free(c);
-            if (errno == 0)
-                /* only possible if 'arg' is a directory */
-                estr = "is a directory";
-            else
-                estr = strerror(errno);
-            errno = oerrno;
-#else
-            if (strcmp(arg, "-") == 0 || app_access(arg, W_OK) == 0
-                || errno == ENOENT)
-                break;
-            estr = strerror(errno);
-#endif
-            BIO_printf(bio_err,
-                       "%s: Cannot open output file %s, %s\n",
-                       prog, arg, estr);
-            return -1;
+            break;
         case 'p':
         case 'n':
             if (!opt_int(arg, &ival)
diff --git a/test/recipes/15-test_out_option.t b/test/recipes/15-test_out_option.t
index f50001d..e1129cc 100644
--- a/test/recipes/15-test_out_option.t
+++ b/test/recipes/15-test_out_option.t
@@ -16,46 +16,49 @@ use OpenSSL::Test::Utils;
 
 setup("test_out_option");
 
-plan skip_all => "'-out' option tests are not available on Windows"
-    if $^O eq 'MSWin32';
-
-plan tests => 11;
-
-# The following patterns should be tested:
-#
-# path        dirname
-# /usr/       /
-# /           /
-# .           .
-# ..          .
-
-test_illegal_path('/usr/');
-test_illegal_path('/');
-test_illegal_path('./');
-test_illegal_path('../');
+# Paths that should generate failure when trying to write to them.
+# Directories are a safe bet for failure on all platforms.
+# Note that directories must end with a slash here, because of how
+# File::Spec massages them into directory specs on some platforms.
+my @failure_paths = (
+    './',
+   );
+my @success_paths = (
+    'randomname.bin'
+   );
 
 # Test for trying to create a file in a non-exist directory
-my @chars = ("A".."Z", "a".."z", "0".."9");
 my $rand_path = "";
-$rand_path .= $chars[rand @chars] for 1..32;
-$rand_path .= "/test.pem";
+do {
+    my @chars = ("A".."Z", "a".."z", "0".."9");
+    $rand_path .= $chars[rand @chars] for 1..32;
+} while (-d File::Spec->catdir('.', $rand_path));
+$rand_path .= "/randomname.bin";
 
-test_illegal_path($rand_path);
-test_legal_path('test.pem');
-unlink 'test.pem';
+push @failure_paths, $rand_path;
 
-sub test_illegal_path {
-    my $path = File::Spec->canonpath($_[0]);
-
-    my $start = time();
-    ok(!run(app([ 'openssl', 'genrsa', '-out', $path, '16384'])), "invalid output path: $path");
-    my $end = time();
-    # The above process should exit in 2 seconds if the path is not valid
-    ok($end - $start < 2, "check time consumed");
+# All explicit cross compilations run a risk of failing this, because the
+# null device provided by perl might not match what the cross compiled
+# application expects to see as a null device.  Therefore, we skip the check
+# of outputing to the null device if the cross compile prefix is set.
+if ((config('CROSS_COMPILE') // '') eq '') {
+    # Check that we can write to the NULL device
+    push @success_paths, File::Spec->devnull();
 }
 
-sub test_legal_path {
-    my $path = File::Spec->canonpath($_[0]);
+plan tests => scalar @failure_paths + scalar @success_paths;
+
+foreach (@failure_paths) {
+    my $path = File::Spec->canonpath($_);
+    ok(!run(app([ 'openssl', 'rand', '-out', $path, '1'])),
+       "invalid output path: $path");
+}
+foreach (@success_paths) {
+    my $path = File::Spec->canonpath($_);
+    ok(run(app([ 'openssl', 'rand', '-out', $path, '1'])),
+       "valid output path: $path");
+}
 
-    ok(run(app([ 'openssl', 'genrsa', '-out', $path, '2048'])), "valid output path: $path");
+END {
+    unlink 'randomname.bin' if -f 'randomname.bin';
 }


More information about the openssl-commits mailing list