Skip to content

Argument escaping of resurrected programs launched with arguments #540

@BirdeeHub

Description

@BirdeeHub

I was notified of this issue with tmux-resurrect in this other issue on my repository, and more useful context might be found there.

This likely happens with any resurrected command that was ran with quoted strings as arguments that contain spaces. So I figured you should be made aware.

I noticed in the error message I was given that it was printing out:

vim -u /nix/store/liy8rn8p5kk9x5661033nvcpwpqzp34h-init.lua --cmd lua vim.g.loaded_node_provider=0;vim.g.loaded_perl_provider=0;vim.g.loaded_python_provider=0;vim.g.python3_host_prog='/nix/store/darvrfhzqs3482gf4316w638gq07x5c0-neovim-0.10.2-myHomeModuleNvim/bin/myHomeModuleNvim-python3';vim.g.ruby_host_prog='/nix/store/darvrfhzqs3482gf4316w638gq07x5c0-neovim-0.10.2-myHomeModuleNvim/bin/myHomeModuleNvim-ruby'; dofile([[/nix/store/dwc3jk10ki03nazyjd463690awpmkl0q-setup.lua]]) default.nix

Followed by

bash: syntax error near unexpected token `[[/nix/store/dwc3jk10ki03nazyjd463690awpmkl0q-setup.lua]]'

It appears that it removed the quotes around the --cmd and threw an error because of it! Or possibly did not escape the ' within the string correctly

It should look like this with the quotes

vim -u /nix/store/liy8rn8p5kk9x5661033nvcpwpqzp34h-init.lua --cmd "lua vim.g.loaded_node_provider=0;vim.g.loaded_perl_provider=0;vim.g.loaded_python_provider=0;vim.g.python3_host_prog='/nix/store/darvrfhzqs3482gf4316w638gq07x5c0-neovim-0.10.2-myHomeModuleNvim/bin/myHomeModuleNvim-python3';vim.g.ruby_host_prog='/nix/store/darvrfhzqs3482gf4316w638gq07x5c0-neovim-0.10.2-myHomeModuleNvim/bin/myHomeModuleNvim-ruby'; dofile([[/nix/store/dwc3jk10ki03nazyjd463690awpmkl0q-setup.lua]])" default.nix

It seems likely that the arguments being restored are being directly printed from argv[whatever] straight to a string?

Those should be escaped and quoted properly before the command is ran again.

Nix will run into this more often, because we often wrap our programs with scripts that launch them with specific arguments.

But this should be a widely applicable issue, that anyone could run into when resurrecting programs started with arguments including a quoted string with spaces in it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions