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

Correctly escape complex shell commands #480

Merged
merged 2 commits into from
Oct 18, 2024
Merged

Correctly escape complex shell commands #480

merged 2 commits into from
Oct 18, 2024

Conversation

smlx
Copy link
Member

@smlx smlx commented Oct 18, 2024

Previously, complex shell commands were not escaped correctly which led to ssh commands like:

ssh example-master@ssh.test.example.com /bin/sh -c '( echo foo; echo bar; echo baz ) | tail -n2'

Returning an error like:

sh: syntax error: unexpected "("

This change implements shell escaping using the algorithm described in ponit 1. of this stack overflow answer to correctly handle complex ssh commands such as the one above.

This uses a shellescape package which implements algorithm 1 described
in https://stackoverflow.com/a/20053121.

This algorithms is essentially: wrap in single quotes, escape any single
quotes.
@smlx smlx added the bug Something isn't working label Oct 18, 2024
@smlx smlx changed the title fix shell escape Correctly escape complex shell commands Oct 18, 2024
@smlx smlx marked this pull request as ready for review October 18, 2024 07:31
@smlx smlx merged commit 1c1557f into main Oct 18, 2024
12 checks passed
@smlx smlx deleted the fix-shell-escape branch October 18, 2024 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant