[openssl] master update

Richard Levitte levitte at openssl.org
Fri Jun 18 07:08:24 UTC 2021


The branch master has been updated
       via  0eed845ce2d76a1f2d8882cb32e1d36c30236d5e (commit)
       via  1abcd1e858ea4b1e924bdd8141d55b889cc2fbc2 (commit)
      from  a205860404f219e4c07424ebe49b817bcaa6d488 (commit)


- Log -----------------------------------------------------------------
commit 0eed845ce2d76a1f2d8882cb32e1d36c30236d5e
Author: Richard Levitte <levitte at openssl.org>
Date:   Wed Jun 16 10:32:43 2021 +0200

    Make util/wrap.pl work better on VMS
    
    Perl's system() on VMS needs to have the command line properly fixed
    up, even with arguments passed in list form.  We arrange that by
    having util/wrap.pl use the same command line fixups as OpenSSL::Test.
    
    As a consequence, util/wrap.pl needs to be generated, to easily pick
    up data from configdata.pm.  This also removes yet another file
    copying hack from the build file templates.
    
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15791)

commit 1abcd1e858ea4b1e924bdd8141d55b889cc2fbc2
Author: Richard Levitte <levitte at openssl.org>
Date:   Wed Jun 16 10:18:20 2021 +0200

    OpenSSL::Test: Move the command line quotifier
    
    The command line quotifier is more useful as a common utility, so it
    gets moved to OpenSSL::Util, as the following two functions:
    
    fixup_cmd_elements(), which is the generic command line reformatter
    fixup_cmd(), which is like fixup_cmd_elements(), but treats the first
    element specially where necessary (such as on VMS).
    
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15791)

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

Summary of changes:
 Configurations/descrip.mms.tmpl      | 14 +-----
 Configurations/unix-Makefile.tmpl    |  6 +--
 Configurations/windows-makefile.tmpl |  6 +--
 util/build.info                      |  3 ++
 util/perl/OpenSSL/Test.pm            | 82 ++++----------------------------
 util/perl/OpenSSL/Util.pm            | 92 +++++++++++++++++++++++++++++++++++-
 util/{wrap.pl => wrap.pl.in}         | 19 +++++++-
 7 files changed, 126 insertions(+), 96 deletions(-)
 rename util/{wrap.pl => wrap.pl.in} (81%)
 mode change 100755 => 100644

diff --git a/Configurations/descrip.mms.tmpl b/Configurations/descrip.mms.tmpl
index 2cf03d0214..bad8e0a776 100644
--- a/Configurations/descrip.mms.tmpl
+++ b/Configurations/descrip.mms.tmpl
@@ -447,7 +447,7 @@ NODEBUG=@
 
 # The main targets ###################################################
 
-{- dependmagic('build_sw'); -} : build_libs_nodep, build_modules_nodep, build_programs_nodep copy-utils
+{- dependmagic('build_sw'); -} : build_libs_nodep, build_modules_nodep, build_programs_nodep
 {- dependmagic('build_libs'); -} : build_libs_nodep
 {- dependmagic('build_modules'); -} : build_modules_nodep
 {- dependmagic('build_programs'); -} : build_programs_nodep
@@ -476,7 +476,7 @@ build_all_generated : $(GENERATED_MANDATORY) $(GENERATED) build_docs
 all : build_sw build_docs
 
 test : tests
-{- dependmagic('tests'); -} : build_programs_nodep, build_modules_nodep copy-utils run_tests
+{- dependmagic('tests'); -} : build_programs_nodep, build_modules_nodep run_tests
 run_tests :
         @ ! {- output_off() if $disabled{tests}; "" -}
         DEFINE SRCTOP "$(SRCDIR)"
@@ -738,16 +738,6 @@ check_INSTALLTOP :
         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
                 EXIT %x10000002
 
-# Helper targets #####################################################
-
-copy-utils : [.util]wrap.pl
-
-[.util]wrap.pl : configdata.pm
-	@ IF "$(SRCDIR)" .NES. "$(BLDDIR)" THEN -
-		CREATE/DIR/LOG [.util]
-	@ IF "$(SRCDIR)" .NES. "$(BLDDIR)" THEN -
-		COPY/LOG ossl_sourceroot:[util]wrap.pl [.util]
-
 # Developer targets ##################################################
 
 debug_logicals :
diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl
index 553e51dfe5..2b894c0928 100644
--- a/Configurations/unix-Makefile.tmpl
+++ b/Configurations/unix-Makefile.tmpl
@@ -1361,10 +1361,9 @@ tar:
 
 # Helper targets #####################################################
 
-link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/wrap.pl \
-            $(BLDDIR)/apps/openssl.cnf
+link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/apps/openssl.cnf
 
-$(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/wrap.pl: configdata.pm
+$(BLDDIR)/util/opensslwrap.sh: configdata.pm
 	@if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
 	    mkdir -p "$(BLDDIR)/util"; \
 	    ln -sf "../$(SRCDIR)/util/`basename "$@"`" "$(BLDDIR)/util"; \
@@ -1924,6 +1923,7 @@ EOF
                            rel2abs($config{builddir}));
       return <<"EOF";
 $script: $sources configdata.pm
+	\$(RM) "$script"
 	\$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
 	    "-o$target{build_file}" $sources > "$script"
 	chmod a+x $script
diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl
index ce64c5c3c1..43b29baab4 100644
--- a/Configurations/windows-makefile.tmpl
+++ b/Configurations/windows-makefile.tmpl
@@ -641,11 +641,7 @@ uninstall_image_docs:
 
 # Helper targets #####################################################
 
-copy-utils: $(BLDDIR)\util\wrap.pl $(BLDDIR)\apps\openssl.cnf
-
-$(BLDDIR)\util\wrap.pl: configdata.pm
-	@if NOT EXIST "$(BLDDIR)\util" mkdir "$(BLDDIR)\util"
-	@if NOT "$(SRCDIR)"=="$(BLDDIR)" copy "$(SRCDIR)\util\$(@F)" "$(BLDDIR)\util"
+copy-utils: $(BLDDIR)\apps\openssl.cnf
 
 $(BLDDIR)\apps\openssl.cnf: configdata.pm
 	@if NOT EXIST "$(BLDDIR)\apps" mkdir "$(BLDDIR)\apps"
diff --git a/util/build.info b/util/build.info
index 65e17a9b87..80120fdae1 100644
--- a/util/build.info
+++ b/util/build.info
@@ -6,3 +6,6 @@ ELSIF[{- $target{build_scheme}->[1] eq "unix" -}]
  SCRIPTS{noinst}=shlib_wrap.sh
  SOURCE[shlib_wrap.sh]=shlib_wrap.sh.in
 ENDIF
+SCRIPTS{noinst}=wrap.pl
+SOURCE[wrap.pl]=wrap.pl.in
+DEPEND[wrap.pl]=../configdata.pm
diff --git a/util/perl/OpenSSL/Test.pm b/util/perl/OpenSSL/Test.pm
index 00aa4d841e..00ef1832d3 100644
--- a/util/perl/OpenSSL/Test.pm
+++ b/util/perl/OpenSSL/Test.pm
@@ -22,7 +22,7 @@ $VERSION = "1.0";
                                          srctop_dir srctop_file
                                          data_file data_dir
                                          result_file result_dir
-                                         pipe with cmdstr quotify
+                                         pipe with cmdstr
                                          openssl_versions
                                          ok_nofips is_nofips isnt_nofips));
 
@@ -69,6 +69,7 @@ use File::Spec::Functions qw/file_name_is_absolute curdir canonpath splitdir
 use File::Path 2.00 qw/rmtree mkpath/;
 use File::Basename;
 use Cwd qw/getcwd abs_path/;
+use OpenSSL::Util;
 
 my $level = 0;
 
@@ -315,7 +316,7 @@ sub cmd {
         my @cmdargs = ( @$cmd );
         my @prog = __wrap_cmd(shift @cmdargs, $opts{exe_shell} // ());
 
-        return __decorate_cmd($num, [ @prog, quotify(@cmdargs) ],
+        return __decorate_cmd($num, [ @prog, fixup_cmd_elements(@cmdargs) ],
                               %opts);
     }
 }
@@ -809,50 +810,6 @@ sub cmdstr {
 
 =over 4
 
-=item B<quotify LIST>
-
-LIST is a list of strings that are going to be used as arguments for a
-command, and makes sure to inject quotes and escapes as necessary depending
-on the content of each string.
-
-This can also be used to put quotes around the executable of a command.
-I<This must never ever be done on VMS.>
-
-=back
-
-=cut
-
-sub quotify {
-    # Unix setup (default if nothing else is mentioned)
-    my $arg_formatter =
-	sub { $_ = shift;
-	      ($_ eq '' || /\s|[\{\}\\\$\[\]\*\?\|\&:;<>]/) ? "'$_'" : $_ };
-
-    if ( $^O eq "VMS") {	# VMS setup
-	$arg_formatter = sub {
-	    $_ = shift;
-	    if ($_ eq '' || /\s|["[:upper:]]/) {
-		s/"/""/g;
-		'"'.$_.'"';
-	    } else {
-		$_;
-	    }
-	};
-    } elsif ( $^O eq "MSWin32") { # MSWin setup
-	$arg_formatter = sub {
-	    $_ = shift;
-	    if ($_ eq '' || /\s|["\|\&\*\;<>]/) {
-		s/(["\\])/\\$1/g;
-		'"'.$_.'"';
-	    } else {
-		$_;
-	    }
-	};
-    }
-
-    return map { $arg_formatter->($_) } @_;
-}
-
 =over 4
 
 =item B<openssl_versions>
@@ -1247,16 +1204,11 @@ sub __wrap_cmd {
         # Otherwise, use the standard wrapper
         my $std_wrapper = __bldtop_file("util", "wrap.pl");
 
-        if ($^O eq "VMS") {
-            # On VMS, running random executables without having a command
-            # symbol means running them with the MCR command.  This is an
-            # old PDP-11 command that stuck around.  So we get a command
-            # running perl running the script.
-            @prefix = ( "MCR", $^X, $std_wrapper );
-        } elsif ($^O eq "MSWin32") {
-            # In the Windows case, we run perl explicitly.  We might not
-            # need it, but that depends on if the user has associated the
-            # '.pl' extension with a perl interpreter, so better be safe.
+        if ($^O eq "VMS" || $^O eq "MSWin32") {
+            # On VMS and Windows, we run the perl executable explicitly,
+            # with necessary fixups.  We might not need that for Windows,
+            # but that depends on if the user has associated the '.pl'
+            # extension with a perl interpreter, so better be safe.
             @prefix = ( __fixup_prg($^X), $std_wrapper );
         } else {
             # Otherwise, we assume Unix semantics, and trust that the #!
@@ -1277,23 +1229,7 @@ sub __wrap_cmd {
 sub __fixup_prg {
     my $prog = shift;
 
-    my $prefix = "";
-
-    if ($^O eq "VMS" ) {
-	$prefix = ($prog =~ /^(?:[\$a-z0-9_]+:)?[<\[]/i ? "mcr " : "mcr []");
-    }
-
-    if (defined($prog)) {
-	# Make sure to quotify the program file on platforms that may
-	# have spaces or similar in their path name.
-	# To our knowledge, VMS is the exception where quotifying should
-	# never happen.
-	($prog) = quotify($prog) unless $^O eq "VMS";
-	return $prefix.$prog;
-    }
-
-    print STDERR "$prog not found\n";
-    return undef;
+    return join(' ', fixup_cmd($prog));
 }
 
 # __decorate_cmd NUM, CMDARRAYREF
diff --git a/util/perl/OpenSSL/Util.pm b/util/perl/OpenSSL/Util.pm
index f8fcb2a351..074bb00d99 100644
--- a/util/perl/OpenSSL/Util.pm
+++ b/util/perl/OpenSSL/Util.pm
@@ -16,7 +16,8 @@ use Exporter;
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 $VERSION = "0.1";
 @ISA = qw(Exporter);
- at EXPORT = qw(cmp_versions quotify1 quotify_l dump_data);
+ at EXPORT = qw(cmp_versions quotify1 quotify_l fixup_cmd_elements fixup_cmd
+             dump_data);
 @EXPORT_OK = qw();
 
 =head1 NAME
@@ -126,6 +127,95 @@ sub quotify_l {
     } @_;
 }
 
+=over 4
+
+=item fixup_cmd_elements LIST
+
+Fixes up the command line elements given by LIST in a platform specific
+manner.
+
+The result of this function is a copy of LIST with strings where quotes and
+escapes have been injected as necessary depending on the content of each
+LIST string.
+
+This can also be used to put quotes around the executable of a command.
+I<This must never ever be done on VMS.>
+
+=back
+
+=cut
+
+sub fixup_cmd_elements {
+    # A formatter for the command arguments, defaulting to the Unix setup
+    my $arg_formatter =
+        sub { $_ = shift;
+              ($_ eq '' || /\s|[\{\}\\\$\[\]\*\?\|\&:;<>]/) ? "'$_'" : $_ };
+
+    if ( $^O eq "VMS") {        # VMS setup
+        $arg_formatter = sub {
+            $_ = shift;
+            if ($_ eq '' || /\s|["[:upper:]]/) {
+                s/"/""/g;
+                '"'.$_.'"';
+            } else {
+                $_;
+            }
+        };
+    } elsif ( $^O eq "MSWin32") { # MSWin setup
+        $arg_formatter = sub {
+            $_ = shift;
+            if ($_ eq '' || /\s|["\|\&\*\;<>]/) {
+                s/(["\\])/\\$1/g;
+                '"'.$_.'"';
+            } else {
+                $_;
+            }
+        };
+    }
+
+    return ( map { $arg_formatter->($_) } @_ );
+}
+
+=over 4
+
+=item fixup_cmd LIST
+
+This is a sibling of fixup_cmd_elements() that expects the LIST to be a
+complete command line.  It does the same thing as fixup_cmd_elements(),
+expect that it treats the first LIST element specially on VMS.
+
+=back
+
+=cut
+
+sub fixup_cmd {
+    return fixup_cmd_elements(@_) unless $^O eq 'VMS';
+
+    # The rest is VMS specific
+    my $prog = shift;
+
+    # On VMS, running random executables without having a command symbol
+    # means running them with the MCR command.  This is an old PDP-11
+    # command that stuck around.
+    # This assumes that we're passed the name of an executable.  This is a
+    # safe assumption for OpenSSL command lines
+    my $prefix = 'MCR';
+
+    if ($prog =~ /^MCR$/i) {
+        # If the first element is "MCR" (independent of case) already, then
+        # we assume that the program it runs is already written the way it
+        # should, and just grab it.
+        $prog = shift;
+    } else {
+        # If the command itself doesn't have a directory spec, make sure
+        # that there is one.  Otherwise, MCR assumes that the program
+        # resides in SYS$SYSTEM:
+        $prog = '[]' . $prog unless $prog =~ /^(?:[\$a-z0-9_]+:)?[<\[]/i;
+    }
+
+    return ( $prefix, $prog, fixup_cmd_elements(@_) );
+}
+
 =item dump_data REF, OPTS
 
 Dump the data from REF into a string that can be evaluated into the same
diff --git a/util/wrap.pl b/util/wrap.pl.in
old mode 100755
new mode 100644
similarity index 81%
rename from util/wrap.pl
rename to util/wrap.pl.in
index 1ca09bfdf4..2ac068ce96
--- a/util/wrap.pl
+++ b/util/wrap.pl.in
@@ -1,4 +1,4 @@
-#! /usr/bin/env perl
+#! {- $config{HASHBANGPERL} -}
 
 use strict;
 use warnings;
@@ -6,6 +6,18 @@ use warnings;
 use File::Basename;
 use File::Spec::Functions;
 
+BEGIN {
+    # This method corresponds exactly to 'use OpenSSL::Util',
+    # but allows us to use a platform specific file spec.
+    require {-
+         use Cwd qw(abs_path);
+
+         "'" . abs_path(catfile($config{sourcedir},
+                                'util', 'perl', 'OpenSSL', 'Util.pm')) . "'";
+         -};
+    OpenSSL::Util->import();
+}
+
 my $there = canonpath(catdir(dirname($0), updir()));
 my $std_engines = catdir($there, 'engines');
 my $std_providers = catdir($there, 'providers');
@@ -22,7 +34,10 @@ $ENV{OPENSSL_CONF} = $std_openssl_conf
 my $use_system = 0;
 my @cmd;
 
-if (-x $unix_shlib_wrap) {
+if ($^O eq 'VMS') {
+    # VMS needs the command to be appropriately quotified
+    @cmd = fixup_cmd(@ARGV);
+} elsif (-x $unix_shlib_wrap) {
     @cmd = ( $unix_shlib_wrap, @ARGV );
 } else {
     # Hope for the best


More information about the openssl-commits mailing list