]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
OpenSSL::Test.pm: Replace all uses of rel2abs() with abs_path()
authorRichard Levitte <levitte@openssl.org>
Mon, 7 Jun 2021 12:10:17 +0000 (14:10 +0200)
committerRichard Levitte <levitte@openssl.org>
Tue, 8 Jun 2021 19:15:00 +0000 (21:15 +0200)
rel2abs() doesn't clean the path well enough, which may lead to odd
results when calculating new paths.  abs_path() works better for this
sort of thing.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15644)

util/perl/OpenSSL/Test.pm

index 6960514ac60b6c0b4f295857e516a228e8c605be..ee6962931b90d055854b2a05f9c207cebe09dae2 100644 (file)
@@ -65,8 +65,7 @@ C<$SRCTOP/test/recipes/99-foo_data/>.
 
 use File::Copy;
 use File::Spec::Functions qw/file_name_is_absolute curdir canonpath splitdir
-                             catdir catfile splitpath catpath devnull abs2rel
-                             rel2abs/;
+                             catdir catfile splitpath catpath devnull abs2rel/;
 use File::Path 2.00 qw/rmtree mkpath/;
 use File::Basename;
 use Cwd qw/getcwd abs_path/;
@@ -1117,8 +1116,8 @@ sub __data_dir {
 sub __cwd {
     my $dir = catdir(shift);
     my %opts = @_;
-    my $abscurdir = rel2abs(curdir());
-    my $absdir = rel2abs($dir);
+    my $abscurdir = abs_path(curdir());
+    my $absdir = abs_path($dir);
     my $reverse = abs2rel($abscurdir, $absdir);
 
     # PARANOIA: if we're not moving anywhere, we do nothing more
@@ -1152,7 +1151,14 @@ sub __cwd {
     my @dirtags = sort keys %directories;
     foreach (@dirtags) {
        if (!file_name_is_absolute($directories{$_})) {
-           my $newpath = abs2rel(rel2abs($directories{$_}), rel2abs($dir));
+           my $oldpath = abs_path($directories{$_});
+           my $newbase = abs_path($dir);
+           my $newpath = abs2rel($oldpath, $newbase);
+           if ($debug) {
+               print STDERR "DEBUG: [dir $_] old path: $oldpath\n";
+               print STDERR "DEBUG: [dir $_] new base: $newbase\n";
+               print STDERR "DEBUG: [dir $_] resulting new path: $newpath\n";
+           }
            $tmp_directories{$_} = $newpath;
        }
     }
@@ -1162,7 +1168,14 @@ sub __cwd {
     # process can use their values properly as well
     foreach (@direnv) {
        if (!file_name_is_absolute($ENV{$_})) {
-           my $newpath = abs2rel(rel2abs($ENV{$_}), rel2abs($dir));
+           my $oldpath = abs_path($ENV{$_});
+           my $newbase = abs_path($dir);
+           my $newpath = abs2rel($oldpath, $newbase);
+           if ($debug) {
+               print STDERR "DEBUG: [env $_] old path: $oldpath\n";
+               print STDERR "DEBUG: [env $_] new base: $newbase\n";
+               print STDERR "DEBUG: [env $_] resulting new path: $newpath\n";
+           }
            $tmp_ENV{$_} = $newpath;
        }
     }
@@ -1182,16 +1195,18 @@ sub __cwd {
 
     if ($debug) {
        print STDERR "DEBUG: __cwd(), directories and files:\n";
-       print STDERR "  \$directories{BLDTEST} = \"$directories{BLDTEST}\"\n";
-       print STDERR "  \$directories{SRCTEST} = \"$directories{SRCTEST}\"\n";
-       print STDERR "  \$directories{SRCDATA} = \"$directories{SRCDATA}\"\n";
-       print STDERR "  \$directories{RESULTS} = \"$directories{RESULTS}\"\n";
-       print STDERR "  \$directories{BLDAPPS} = \"$directories{BLDAPPS}\"\n";
-       print STDERR "  \$directories{SRCAPPS} = \"$directories{SRCAPPS}\"\n";
-       print STDERR "  \$directories{SRCTOP}  = \"$directories{SRCTOP}\"\n";
-       print STDERR "  \$directories{BLDTOP}  = \"$directories{BLDTOP}\"\n";
+       print STDERR "  Moving from $abscurdir\n";
+       print STDERR "  Moving to $absdir\n";
+       print STDERR "\n";
+       print STDERR "  \$directories{BLDTEST} = \"$directories{BLDTEST}\"\n";
+       print STDERR "  \$directories{SRCTEST} = \"$directories{SRCTEST}\"\n";
+       print STDERR "  \$directories{SRCDATA} = \"$directories{SRCDATA}\"\n";
+       print STDERR "  \$directories{RESULTS} = \"$directories{RESULTS}\"\n";
+       print STDERR "  \$directories{BLDAPPS} = \"$directories{BLDAPPS}\"\n";
+       print STDERR "  \$directories{SRCAPPS} = \"$directories{SRCAPPS}\"\n";
+       print STDERR "  \$directories{SRCTOP}  = \"$directories{SRCTOP}\"\n";
+       print STDERR "  \$directories{BLDTOP}  = \"$directories{BLDTOP}\"\n";
        print STDERR "\n";
-       print STDERR "  current directory is \"",curdir(),"\"\n";
        print STDERR "  the way back is \"$reverse\"\n";
     }