-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Wrap commands cont. ';' in sh when $SHELL == zsh #635
Wrap commands cont. ';' in sh when $SHELL == zsh #635
Conversation
works around issues of zsh+tmux and strange handling of SIGINT
Appreciate this is a gnarly PR owing to the foul shell escaping. It might be worth going down the wrap-with-sh path even when $SHELL != zsh and/or when command doesn't contain I'm also open to cleaner ways of detecting if the user's shell is zsh |
Wouldn't it be cleaner to always use Separately, it's probably a good plan to discontinue the use of |
if 'zsh' in os.environ['SHELL'] and ';' in command: | ||
# zsh and tmux have issues with handling SIGINT | ||
# wrapping command with sh -c (and escaping single quotes) works around this | ||
command = "sh -c '" + command.replace("\\", "\\\\").replace("'", "'\\\\\\''") + "'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have sh_escape
for exactly this reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll take a look
@zachriggle said:
If you mean "avoid doing If you mean "always go down the path of wrapping splitw'd commands with
Probably a good idea. This is the tack I took in #628 but it ended up feeling pretty hacky, and when I found out the issue only bites (as far as I've seen) zsh+tmux users, I thought the fix could be better targeted. I'd support having |
All the tests I cooked up still pass except for:
I was probably too ambitious with my escaping of |
Could you reopen this PR against the dev branch? |
Or perhaps against the stable branch? Is it a bugfix or a feature? |
* * Invoke heap command only with libc debug symbols. * changed message
Preface: I might be going about this all the wrong way, but this is a personal workaround for something that annoys me a lot. Others' mileage may vary.
tmux and zsh seem to have issues with SIGINT and I don't know whose fault it is, or if it's working as designed on their behalf.
This behaviour manifests when
run_in_new_terminal()
is told to runfoo;bar
(e.g. when we call gdb with a-x
'd script and try to clean the script up after gdb exits - seepwntools/pwnlib/gdb.py
Line 310 in fc5b7b9
It only seems to occur when the user's shell is zsh.
Minimal reproducer for this behaviour:
Hit Ctrl-C on man's pager and resize the pane. Everything is ok.
Hit Ctrl-C on man's pager and resize the pane. The pane disappears.
In the second case above, tmux is doing
zsh -c 'man ascii;id'
and zsh within tmux is seemingly interfering with the SIGINT that Ctrl-C sends.The workaround
In
run_in_new_terminal()
, when we're heading down thetmux split
path AND the user's shell iszsh
ANDcommand
contains;
(we're probably trying to do more than one thing at a time) then wrap everything insh -c ''
and go through escaping hell to handle'
and\
within commands properly.It might be worth using this workaround more often or all the time to simplify code path flow and maximise code coverage, but this will result in a lot of "useless" invocations of
sh
.Tests
pwn.gdb.attach()
on a non-pwnlib managed processBoth invocations of gdb worked, and the panes were resizable with and without doing Ctrl-C beforehand.
/tmp/pwnoAz___.gdb
got cleaned up.pwn.gdb.attach()
on a pwnlib-managed process viapwnlib.tubes.process
Both invocations of gdb worked, and the panes were resizable with and without doing Ctrl-C beforehand.
/tmp/pwnhXCVPI.gdb
got cleaned up.pwn.gdb.attach()
on a pwnlib-managed process viapwnlib.tubes.ssh
using password authenticationBoth invocations of gdb worked, and the panes were resizable with and without doing Ctrl-C beforehand. An empty tempfile and a tempfile containing
continue
got left on the remote host (see #629 which I need to revisit)pwn.gdb.attach()
on a pwnlib-managed process viapwnlib.tubes.ssh
using key authenticationNot sure what happened to the first
pwn.gdb.attach()
but I tried it again for with fingers crossed and it worked:The second and third invocations of gdb worked, and the panes were resizable with and without doing Ctrl-C beforehand. Two empty tempfiles and a tempfile containing
continue
got left on the remote host (see #629 which I need to revisit)Creating some files:
/tmp/ab
gets touched/tmp/a'b
does not get touched. This is an existing escaping bug outside of what this PR modifies (we're not hitting the new code because command doesn't contain;
), and probably warrants attention./tmp/abc
gets touched/tmp/a'bc
gets touched/tmp/a\'bc
gets touched