Skip to content
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

crash when starting user command if used MINTTY_... variable contains tab char? #1269

Closed
mkq opened this issue Jun 11, 2024 · 6 comments
Closed
Labels

Comments

@mkq
Copy link

mkq commented Jun 11, 2024

For a long time, I sometimes had mintty crash when invoking a user command. Now I have finally narrowed the problem down to write a proper bug report.

mintty version: 3.7.1 (x86_64-pc-cygwin) [Windows 22631]

Preparation:

Put this in an executable script called mintty-usercmd-test in $PATH:

#!/bin/bash
cmd='less <<<"${MINTTY_BUFFER}"'
mintty --class mintty-usercmd -p left -s 100,30 -o 'BackgroundColour=#fff0dc' \
	-t "mintty user command $(date  %T) ($MINTTY_TITLE)" -e env bash -c "$cmd" &

Set UserCommands=�&test:mintty-usercmd-test (first char after "=" is Ctrl a) and MenuMenu=u in ~/.minttyrc.

Steps to reproduce:

  1. Run c:\cygwin\bin\mintty.exe -e env HOME=/tmp bash
  2. Inside mintty, execute printf 'a\tb\n'
  3. Press context menu key, then T
    ⇒ mintty crashes.

Notes

  1. Same with printf 'a b\n' (space instead of tab) works.
  2. Since I have WSL installed, a bash command might not be the intended Cygwin bash. But I think it is, because pstree -ha shows
 ├─mintty --class mintty-usercmd -p left -s 100,30 -o BackgroundColour=#fff0dc -t mintty user command 18:36:58 (/usr/bin) -e env bash -c less <<<"${MINTTY_BUFFER}"
 │   └─bash -c less <<<"${MINTTY_BUFFER}"
 │       └─less
@mintty
Copy link
Owner

mintty commented Jun 11, 2024

Note that option UserCommands is deprecated - does it also happen with CtxMenuCommands?
Your invocation step 1. suggests you're starting mintty from a Windows cmd. In that case however, you'd normally not have env or bash in the path, so your path may be extended to include the cygwin bin directory? Also the cygwin path, for access to the test script, may not be included in that case. So the test case isn't yet fully described and I cannot reproduce it right now.
About note 2: which bash do you actually get? (uname) Say /bin/bash to make sure you're getting cygwin bash.

@mintty
Copy link
Owner

mintty commented Jun 12, 2024

Also, as long as I can't reproduce this, please try to strip down the test case further:

  • mintty parameters (is -t needed?)
  • same effect if the menu item is selected by mouse rather than key?
  • Is the Ctrl a in UserCommands needed?
  • Is the env command needed?
  • Since an issue with "here strings" (<<<) was recently reported on the cygwin mailing list, replace that with echo "$MINTTY_BUFFER" | less
  • By "crash" you mean that the first mintty (the one to open the context menu, not the one started from the script) gets terminated? Can you build a debug version (make DEBUG=1) and provide the stacktrace?

@mkq
Copy link
Author

mkq commented Jun 12, 2024

Thanks for looking into this! First, good news:

CopyTab option

I have narrowed the issue down to a ~/.minttyrc with only these two lines:

CtxMenuFunctions=&test:`mintty-usercmd-test`;
CopyTab=yes

mintty only crashes with the CopyTab=yes option.

Answers

Before I found out about CopyTab, I already wrote down answers to your questions. Maybe you don't need them anymore, but here they are:

By "crash" you mean that the first mintty (the one to open the context menu, not the one started from the script) gets terminated?

Yes.

Your invocation step 1. suggests you're starting mintty from a Windows cmd. In that case however, you'd normally not have env or bash in the path, so your path may be extended to include the cygwin bin directory? Also the cygwin path, for access to the test script, may not be included in that case. So the test case isn't yet fully described and I cannot reproduce it right now.

But all that would equally apply to note 1 "Same with printf 'a b\n' (space instead of tab) works". By that I meant: The new mintty instance starts and runs less with the expected contents. So my PATH is not the problem, and I should probably just have left out note 2, which is probably irrelevant. In the meantime, I have verified with a deliberately (not by my test script) startet WSL bash, that Cygwin pstree does not show WSL bash, so the bash inside the user command is really Cygwin.

About note 2: which bash do you actually get? (uname) Say /bin/bash to make sure you're getting cygwin bash.

"CYGWIN_NT-10.0-22631 <my hostname> 3.5.1-1.x86_64 2024-02-27 11:54 UTC x86_64 Cygwin"
This is from within the test script invoked as a user command. (I added uname -a >> /tmp/uname.log; to the bash -c.)

mintty parameters (is -t needed?)

No. This mintty-usercmd-test is also sufficient to crash:

#!/bin/bash
cmd='less <<<"${MINTTY_BUFFER}"'
mintty -e env bash -c "$cmd" &

same effect if the menu item is selected by mouse rather than key?

Yes.

  • Opening the context menu by key, then clicking it with the mouse: crashes too.
  • I commented out MenuCtrlMenu option in ~/.minttyrc and started the user command with Ctrl RMB, then LMB on "test": crashes too.

Is the Ctrl a in UserCommands needed?

No. Same behavior without it. That was just the separator I usually use when I have multiple user commands configured.

Is the env command needed?

No. This mintty-usercmd-test is also sufficient to crash:

#!/bin/bash
cmd='less <<<"${MINTTY_BUFFER}"'
mintty -e bash -c "$cmd" &

Since an issue with "here strings" (<<<) was recently reported on the cygwin mailing list, replace that with echo "$MINTTY_BUFFER" | less

Still crashes with

#!/bin/bash
cmd='echo "${MINTTY_BUFFER}" | less'
mintty -e bash -c "$cmd" &

Note that option UserCommands is deprecated - does it also happen with CtxMenuCommands?

Yes. I checked with

CtxMenuFunctions=&test:`mintty-usercmd-test`;

Can you build a debug version (make DEBUG=1) and provide the stacktrace?

I have built it, but Windows Security does not let me start it yet. I probably will in a few days, though.

@mintty mintty added the bug label Jun 13, 2024
@mintty
Copy link
Owner

mintty commented Jun 13, 2024

Thanks. And the extra script isn't needed either, the following config is sufficient:

UserCommands=copy with tabs:copy-tabs
CopyTab=yes

@mintty
Copy link
Owner

mintty commented Jun 13, 2024

UserCommands=copy with tabs:copy-tabs

I confused config features here. But actually UserCommands=any cmd:true is sufficient.

@mintty
Copy link
Owner

mintty commented Jun 26, 2024

Released 3.7.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants