From 6842dbf066975e7fdcd6dfc19d078a62b78f8285 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Wed, 21 Mar 2012 17:19:12 -0400 Subject: [PATCH] Startup script quoting cleanups per Anders Kaseorg --- scripts/mosh | 12 ++++-------- src/frontend/mosh-server.cc | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/scripts/mosh b/scripts/mosh index a8163bd..6e006e0 100755 --- a/scripts/mosh +++ b/scripts/mosh @@ -197,16 +197,10 @@ if ( $pid == 0 ) { # child } if ( scalar @command > 0 ) { - my $command_string = join ' ', @command; - $command_string =~ s'\$'\$'g; - $command_string =~ s'`'\`'g; - $command_string =~ s'"'\"'g; - $command_string =~ s'\\'\\'g; - - push @server, ( '--', '/bin/sh', '-c', qq{"$command_string"} ); + push @server, '--', @command; } - exec 'ssh', '-S', 'none', '-o', "ProxyCommand=$0 --fake-proxy -- %h %p", '-t', $userhost, '--', @server; + exec 'ssh', '-S', 'none', '-o', "ProxyCommand=$0 --fake-proxy -- %h %p", '-t', $userhost, '--', shell_quote( @server ); die "Cannot exec ssh: $!\n"; } else { # server my ( $ip, $port, $key ); @@ -240,3 +234,5 @@ if ( $pid == 0 ) { # child $ENV{ 'MOSH_PREDICTION_DISPLAY' } = $predict; exec {$client} ($client, $ip, $port); } + +sub shell_quote { join ' ', map {(my $a = $_) =~ s/'/'\\''/g; "'$a'"} @_ } diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index ad8aefb..55fa389 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -316,8 +316,8 @@ int run_server( const char *desired_ip, const char *desired_port, command[ 0 ] = strdup( argv0.c_str() ); fatal_assert( command[ 0 ] ); - if ( execv( executable.c_str(), command ) < 0 ) { - perror( "execve" ); + if ( execvp( executable.c_str(), command ) < 0 ) { + perror( "execvp" ); exit( 1 ); } exit( 0 );