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

Remove escapes causing malformed scripts #906

Merged
merged 1 commit into from
Aug 15, 2019
Merged

Remove escapes causing malformed scripts #906

merged 1 commit into from
Aug 15, 2019

Conversation

ChristianJacobsen
Copy link
Contributor

@ChristianJacobsen ChristianJacobsen commented Aug 6, 2019

As mentioned is this issue and others, the backslash- and doublequote-escape in this command is causing malformed scripts to be generated which will in turn fail to run. This makes it impossible to attach to processes as gdb can't elevate its permissions.

The current implementation generates this file:

echo $$ > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; cd /home/jenkins/code/misc/c++_node_grpc_test/server ; DbgTerm=`tty` ; set -o monitor ; trap 'rm /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 /tmp/Microsoft-MIEngine-Cmd-2md1t9rp.9ee' EXIT ; read -n 1 -p \"Superuser access is required to attach to a process. Attaching as superuser can potentially harm your computer. Do you want to continue? [y/N]\" yn; if [[ ! $yn =~ ^[Yy]$ ]] ; then exit 0; fi; /usr/bin/pkexec /sbin/gdb --interpreter=mi --tty=$DbgTerm < /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q > /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb & clear; pid=$! ; echo $pid > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; wait $pid; 

The proposed change will generate this file, which is valid:

echo $$ > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; cd /home/jenkins/code/misc/c++_node_grpc_test/server ; DbgTerm=`tty` ; set -o monitor ; trap 'rm /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 /tmp/Microsoft-MIEngine-Cmd-2md1t9rp.9ee' EXIT ; read -n 1 -p "Superuser access is required to attach to a process. Attaching as superuser can potentially harm your computer. Do you want to continue? [y/N]" yn; if [[ ! $yn =~ ^[Yy]$ ]] ; then exit 0; fi; /usr/bin/pkexec /sbin/gdb --interpreter=mi --tty=$DbgTerm < /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q > /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb & clear; pid=$! ; echo $pid > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; wait $pid; 

Disregard the file-system paths in the provided examples as they are only relevant to my file-system.

As mentioned is [this](microsoft/vscode-cpptools#3711) issue and others, the backslash- and doublequote-escape in this command is causing malformed scripts that will fail to run. This makes it impossible to attach to processes as gdb can't elevate it's permissions.

The current implementation generates this file:
```bash
echo $$ > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; cd /home/jenkins/code/misc/c++_node_grpc_test/server ; DbgTerm=`tty` ; set -o monitor ; trap 'rm /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 /tmp/Microsoft-MIEngine-Cmd-2md1t9rp.9ee' EXIT ; read -n 1 -p \"Superuser access is required to attach to a process. Attaching as superuser can potentially harm your computer. Do you want to continue? [y/N]\" yn; if [[ ! $yn =~ ^[Yy]$ ]] ; then exit 0; fi; /usr/bin/pkexec /sbin/gdb --interpreter=mi --tty=$DbgTerm < /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q > /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb & clear; pid=$! ; echo $pid > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; wait $pid; 
```

The proposed change will generate this file, which is valid:
```
echo $$ > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; cd /home/jenkins/code/misc/c++_node_grpc_test/server ; DbgTerm=`tty` ; set -o monitor ; trap 'rm /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 /tmp/Microsoft-MIEngine-Cmd-2md1t9rp.9ee' EXIT ; read -n 1 -p "Superuser access is required to attach to a process. Attaching as superuser can potentially harm your computer. Do you want to continue? [y/N]" yn; if [[ ! $yn =~ ^[Yy]$ ]] ; then exit 0; fi; /usr/bin/pkexec /sbin/gdb --interpreter=mi --tty=$DbgTerm < /tmp/Microsoft-MIEngine-In-yfl0fzxv.e1q > /tmp/Microsoft-MIEngine-Out-vbd9a98g.bjb & clear; pid=$! ; echo $pid > /tmp/Microsoft-MIEngine-Pid-hp0n9b2a.oc4 ; wait $pid; 
```

Disregard the file-system paths in the provided examples as they are only relevant to my file-system.
@pieandcakes
Copy link
Collaborator

pieandcakes commented Aug 6, 2019

@ChristianJacobsen Can you let us know what testing has been done and on which OSs?

Thank you for your contribution!

@pieandcakes pieandcakes self-assigned this Aug 6, 2019
@pieandcakes pieandcakes added the bug label Aug 6, 2019
@ChristianJacobsen
Copy link
Contributor Author

Hi. This has, unfortunately, not received any testing from me apart from my general understanding of shell scripts and seeing the output generated. I, for one, don't know how to build, nor link, this piece of software to work with the VSCode CPP Extension. C# is generally outside my domain apart from the occasional Unity fun.

I was able to intercept the initial reading of the file by halting my shell, editing the generated file, and then letting it continue. This resulted in a successful attach.

OS is Arch Linux running kernel 5.2.6-arch1-1-ARCH, VSCode is 1.36.1 2213894ea0415ee8c85c5eea0d0ff81ecc191529 x64, and lastly the VSCode CPP Extension is 0.24.1.

If there's anything else, including testing (given some instructions), that I can do - then I'm more than happy to help.

Thanks for getting to my PR as fast as you did :)

@pieandcakes
Copy link
Collaborator

@ChristianJacobsen Thanks for the info. I'll try and give it a test when I have some spare cycles.

@ChristianJacobsen
Copy link
Contributor Author

Sounds good to me, @pieandcakes!
Tag me if you need me :)

@pieandcakes pieandcakes merged commit 597e41f into microsoft:master Aug 15, 2019
@ChristianJacobsen ChristianJacobsen deleted the patch-1 branch August 16, 2019 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants