From 4c7200c016bf29d6e4c4fcbbc0305d0743642096 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 9 May 2016 03:01:32 -0400 Subject: [PATCH] --experimental-remote-ip=local: Substitute the IP more carefully For example, do not interpret regex metacharacters within the hostname, and avoid accidentally matching the username part of username@hostname when they happen to match. Signed-off-by: Anders Kaseorg --- scripts/mosh.pl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/mosh.pl b/scripts/mosh.pl index c6fc632..b89086a 100755 --- a/scripts/mosh.pl +++ b/scripts/mosh.pl @@ -302,11 +302,7 @@ $ENV{ 'MOSH_CLIENT_PID' } = $$; # We don't support this, but it's useful for tes my $ip; if ( $use_remote_ip eq 'local' ) { # "parse" the host from what the user gave us - my $host = $userhost; - $host =~ s/.*@//; - if ( !defined $host ) { - die( "could not find hostname in $userhost" ); - } + my ($user, $host) = $userhost =~ /^((?:.*@)?)(.*)$/; # get list of addresses my @res = resolvename( $host, 22, $family ); # Use only the first address as the Mosh IP @@ -319,7 +315,7 @@ if ( $use_remote_ip eq 'local' ) { die( "could not use address for $host" ); } $ip = $addr_string; - $userhost =~ s/${host}/${ip}/; + $userhost = "$user$ip"; } my $pid = open(my $pipe, "-|");