NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.5k stars 1.5k forks source link

Incorrect NIX_SSHOPTS parsing when option value contains string literals with whitespace inside #5181

Open corpix opened 3 years ago

corpix commented 3 years ago

With NIX_SSHOPTS='-o ProxyCommand="ssh -W %h:%p ..."' nix-copy-closure tool will fail with error.

I believe this is because tokenizer result added as arguments without additional transformations, making values with string literals

-o ProxyCommand="ssh -W %h:%p ..."

look like this

list of 5 elements, I used , as a delimiter here

[-o, ProxyCommand="ssh, -W, %h:%p, ..."]

Steps To Reproduce

Run

NIX_SSHOPTS='-o ProxyCommand="echo 1 2"' nix-copy-closure whatever@example.com /nix/store/czmlm5fsnqg7jw4f7323aqgrllwhfd6v-nixos-system-0-21.11pre-git

On my system this fails:

fish: Unexpected end of string, quotes are not balanced
exec "echo
     ^

kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535
error: cannot connect to 'whatever@example.com'

When using bash as a SHELL:

/nix/store/39k586qrghljxiyqvv72ni5fk89vshib-bash-interactive-4.4-p23/bin/bash: -c: line 0: unexpected EOF while looking for matching `"'
/nix/store/39k586qrghljxiyqvv72ni5fk89vshib-bash-interactive-4.4-p23/bin/bash: -c: line 1: syntax error: unexpected end of file
...

Expected behavior

NIX_SSHOPTS should be parsed with honor to nested string literals:

-o ProxyCommand="ssh -W %h:%p ..."

should become

list of 2 elements, I used , as a delimiter here

[-o, ProxyCommand="ssh -W %h:%p ..."]
stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info