From 7cb046e80c3d60edd79c5af5ac297b64fcab0544 Mon Sep 17 00:00:00 2001 From: "Christian A. Jacobsen" Date: Tue, 6 Aug 2019 19:58:55 +0200 Subject: [PATCH] Remove escapes causing malformed scripts As mentioned is [this](https://github.com/microsoft/vscode-cpptools/issues/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. --- src/MICore/UnixUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MICore/UnixUtilities.cs b/src/MICore/UnixUtilities.cs index 6b1062bd3..0e3923172 100644 --- a/src/MICore/UnixUtilities.cs +++ b/src/MICore/UnixUtilities.cs @@ -76,7 +76,7 @@ internal static string GetDebuggerCommand(LocalLaunchOptions localOptions) // If the system doesn't allow a non-root process to attach to another process, try to run GDB as root if (localOptions.ProcessId.HasValue && !isRoot && UnixUtilities.GetRequiresRootAttach(localOptions.DebuggerMIMode)) { - prompt = String.Format(CultureInfo.CurrentCulture, "read -n 1 -p \\\"{0}\\\" yn; if [[ ! $yn =~ ^[Yy]$ ]] ; then exit 0; fi; ", MICoreResources.Warn_AttachAsRootProcess); + prompt = String.Format(CultureInfo.CurrentCulture, "read -n 1 -p \"{0}\" yn; if [[ ! $yn =~ ^[Yy]$ ]] ; then exit 0; fi; ", MICoreResources.Warn_AttachAsRootProcess); // Prefer pkexec for a nice graphical prompt, but fall back to sudo if it's not available if (File.Exists(UnixUtilities.PKExecPath))