Commits

Shlomi Fish  committed ef9b688

Convert xsystem to use a list of arguments instead of a single string.

This is more secure and less error prone.

  • Participants
  • Parent commits 6a009d9

Comments (0)

Files changed (1)

 }
 
 sub xsystem {
-    my $command = shift;
+    my $command_aref = shift;
     if ($DEBUG) {
-        print $command, "\n";
-        if (system($command) != 0) {
-            die "system call to '$command' failed";
+        print "@$command_aref\n";
+        if ((system { $command_aref->[0] } @$command_aref) != 0) {
+            die "system call to '@$command_aref' failed";
         }
         return 1;
     }
     open(OLDERR, ">&STDERR");
     open(STDOUT, ">$DEVNULL");
     open(STDERR, ">$DEVNULL");
-    my $retval = system($command);
+    my $retval = (system { $command_aref->[0] } @$command_aref);
     open(STDOUT, ">&OLDOUT");
     open(STDERR, ">&OLDERR");
     if ($retval != 0) {
-        die "system call to '$command' failed";
+        die "system call to '@$command_aref' failed";
     }
     return 1;
 }
         close($cfile);
     }
     my $quote = $is_Win32 ? '"' : "'";
-    xsystem("$^X Makefile.PL "
-        . join(' ', map { "${quote}$_=$config{$_}${quote}" } keys %config)
+    xsystem([$^X, 'Makefile.PL',
+        (map { "$_=$config{$_}" } keys %config),
+        ]
     );
 
     my $def_opt = defined($opt) ? $opt : '';
     # libraries to include do not belong here!
     # I would assume a user to set OTHERLDFLAGS in the %config if they are
     # really required. if done so, we don't have to pass them here ...
-    xsystem("$Config{make} test ${quote}OTHERLDFLAGS=${def_opt}${quote}");
+    xsystem([$Config{make}, 'test', "OTHERLDFLAGS=${def_opt}"]);
 } # end try_link0
 
 sub try_link {