-
-
Notifications
You must be signed in to change notification settings - Fork 84
Fix NUL character introducing escape secuence for octal values #5
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
Conversation
We now use hex escape to inject the NUL character. NUL characters start escape sequence for inserting a byte given its octal value. This caused problems when environment variables had digit values. For example, if the value of the variable SSH_AGENT_PID is "46", the command `printf "\046"` would result, and the output would be `&`, as 046 is the octal value for the ampersand character.
Ah, thanks for finding this bug! I'm not sure that hexadecimal escapes are the best solution, since they do not seem to be supported everywhere. The man page for
so it looks like -Steve |
I made a change to use |
It works as well on mine. Thank you. |
Great! That must have been an adventure to debug... |
Hi, I've also had some issues regarding the NUL character. It works fine using bash as $SHELL, but I'm using fish on OS X. The only variant I could make it work was to replace the NUL of Like this: (defun exec-path-from-shell-printf (str)
"Return the result of printing STR in the user's shell.
Executes $SHELL as interactive login shell.
STR is inserted literally in a double-quoted argument to printf,
and may therefore contain backslashed escape sequences, but must not
contain the '%' character."
(with-temp-buffer
(call-process (getenv "SHELL") nil (current-buffer) nil
"--login" "-i" "-c" (concat "printf \"__RESULT:" str "\""))
(goto-char (point-min))
(when (re-search-forward "__RESULT:\\(.*\\)" nil t)
(match-string 1)))) \0 works fine for the string-splitting in the other functions, though. |
fish's Maybe using |
I'm a bit wary of adopting any approach which looks for binaries in specific places. The best solution would be to understand what's going on with fish. But in any case I found an issue with my existing code, in that the null character was actually passed to the shell in a double-quoted string, so it was the shell that interpreted it, not |
Unfortunately not. Let's disect the what's going on: The
The same command in bash (or zsh or csh) gives me:
Quite a difference. fish outputs the path as a list (not separated by colons), maybe that's the underlying problem? I suppose there is no easy solution to that. |
Yes, there's not going to be an easy way to work around that unusual behaviour! |
I don't know if it's helpful, but I found this gist that works around the path issue with fish. |
…lt-in The hope is that this might allow fish to work. See #5.
It works! Thanks so much! |
Thanks, nice to see this fixed. |
We now use hex escape to inject the NUL character.
NUL characters start escape sequence for inserting a byte given its octal
value. This caused problems when environment variables had digit values. For
example, if the value of the variable SSH_AGENT_PID is "46", the command
printf "\046"
would result, and the output would be&
, as 046 is the octalvalue for the ampersand character.