Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Special characters handling on Linux #131

Open
darkk opened this issue Oct 9, 2020 · 0 comments
Open

Special characters handling on Linux #131

darkk opened this issue Oct 9, 2020 · 0 comments

Comments

@darkk
Copy link

darkk commented Oct 9, 2020

Linux has the following command generated while running node test.js (newlines added after ; for readability):

cd "/mnt/sudo-prompt";
export SUDO_PROMPT_TEST_ENV="hello world";
"/usr/bin/pkexec" --disable-internal-agent /bin/bash -c "echo SUDOPROMPT; echo \"$SUDO_PROMPT_TEST_ENV\""

The command has the following issues:

  • pkexec changes workdir to /root, so the code fails to preserve CWD as cd is done in an "outer" shell and does not propagate through pkexec
  • SUDO_PROMPT_TEST_ENV does not come from pkexec'ed environment, it comes from an "outer" shell. So, command env | grep ^SUDO_PROMPT_TEST_ENV= shows nothing
  • working directory is wrapped with double quotes, so shell variable expansion is applied, e.g. the code fails to run in a directory named /mnt/$udo-prompt" with stderr: "/bin/sh: 1: cd: can't cd to /mnt/-prompt\n"
  • variable value is wrapped with double quotes, so shell variable expansion is applied there as well

I can provide a PR with fixes, but some of the fixes may break backwards compatibility, and I ask for some guidance from the maintainer before submitting a PR.

  1. may command echo "$PATH" change the behavior and show after-sudo PATH instead of before-sudo PATH? It refers to the difference between the following commands:
$ sudo sh -c "echo $HOME"
/home/node
$ sudo sh -c 'echo $HOME'
/root
  1. may env {name: 'something like $million'} change the behavior and preserve $million as-is instead of doing shell variable expansion?
  2. may the command be skipped if the script fails to change the directory?
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant