Small fix in OpenSSL::Test
authorRichard Levitte <levitte@openssl.org>
Thu, 3 Sep 2015 17:41:40 +0000 (19:41 +0200)
committerRichard Levitte <levitte@openssl.org>
Mon, 7 Sep 2015 14:10:58 +0000 (16:10 +0200)
Be careful when shifting in a function argument, you end up changing
the caller's value.  Instead, when it is an array, make a shallow copy
and shift in that instead.

Reviewed-by: Rich Salz <rsalz@openssl.org>
test/testlib/OpenSSL/Test.pm

index 83d7acc8b7cedfacf568425781f1feb9e70a21a0..f378351f6575925811d3b777c1e34caf49743619 100644 (file)
@@ -695,8 +695,10 @@ sub __build_cmd {
 
     my $num = shift;
     my $path_builder = shift;
-    my $cmd = __fixup_cmd($path_builder->(shift @{$_[0]}));
-    my @args = @{$_[0]}; shift;
+    # Make a copy to not destroy the caller's array
+    my @cmdarray = ( @{$_[0]} ); shift;
+    my $cmd = __fixup_cmd($path_builder->(shift @cmdarray));
+    my @args = @cmdarray;
     my %opts = @_;
 
     return () if !$cmd;