Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mosh.pl: Allow shell expansion of --server with --local #947

Merged
merged 1 commit into from
Dec 8, 2017

Conversation

andersk
Copy link
Member

@andersk andersk commented Dec 3, 2017

Fixes #946, matching the behavior of --server without --local.

Fixes mobile-shell#946, matching the behavior of --server without --local.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@@ -396,7 +396,7 @@ sub predict_check {
delete $ENV{ 'SSH_CONNECTION' };
chdir; # $HOME
print "MOSH IP ${userhost}\n";
exec( $server, @server );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, is there any reason to use shell_quote() here at all? We could just do exec( "server " . join( " ", @server ), since we're not running ssh here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joining an array with spaces and no quoting is always the wrong thing to do. It’s a fundamentally lossy operation. In this case, it would manifest by corrupting @command: mosh --local ::1 -- cmd 'arg with spaces' would result in cmd arg with spaces. Even if that bug weren’t as easy to manifest as it is, it would still be locally a bug. Don’t do it. Don’t dooo ittt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plead stupid, your honor. (I couldn't sleep. I got up and posted that. Went back to bed, five minutes later realized it was the wrong thing.)

I'll wait for a response from @TomiBelan before pulling though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (unsurprisingly...), though as I mentioned I didn't test it myself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at this again, this code does break if there's a separator or metacharacter in the executable pathname (such as /Users/cgull/spacey directory/mosh/src/frontend/mosh-server). I believe it should be exec( shell_quote( $server, @server ) ), so as to quote the executable name too. I think I'm understanding Perl correctly here. @andersk, concur?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't sound right. If the goal is to make --server='env foo=bar mosh-server' work with and without --local, then spaces in $server should not be quoted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, like @TomiBelan said, --server is intentionally passed without quoting so the shell can split it (19884d6), and the point of this PR is to fix --local to match that behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started looking at a shell quoting problem in src/tests that this interacts with and forgot about the original problem...

Pulled now.

@cgull
Copy link
Member

cgull commented Dec 5, 2017

@TomiBelan: I still want to know what your use case is-- is it just devel/experimental use of Mosh, or have you got some weird situation where mosh --local helps you use Mosh where mosh localhost wouldn't work?

@TomiBelan
Copy link

Oh, I misunderstood and thought you want my response to this PR. I commented in #946.

@cgull cgull merged commit d4ce0d4 into mobile-shell:master Dec 8, 2017
@eminence eminence added this to the 1.4.0 milestone Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--local can't be used with --server if it contains spaces
4 participants