From 7896c30508aa15133b9df94374eba16498d526de Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 31 Oct 2020 13:18:12 +0100 Subject: [PATCH] Fix cmdline parameter escape --- libs/backends/jack/jack_utils.cc | 11 +++++++++-- libs/pbd/system_exec.cc | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/backends/jack/jack_utils.cc b/libs/backends/jack/jack_utils.cc index 66255968e0..f7d75a4a79 100644 --- a/libs/backends/jack/jack_utils.cc +++ b/libs/backends/jack/jack_utils.cc @@ -631,9 +631,16 @@ ARDOUR::get_jack_default_server_path (std::string& server_path) return true; } -string -quote_string (const string& str) +static string +quote_string (string str) { + /* escape quotes in string */ + size_t pos = 0; + while ((pos = str.find("\"", pos)) != std::string::npos) { + str.replace (pos, 1, "\\\""); + pos += 2; + } + /* and quote the whole string */ return "\"" + str + "\""; } diff --git a/libs/pbd/system_exec.cc b/libs/pbd/system_exec.cc index d1079a311f..cec58504ae 100644 --- a/libs/pbd/system_exec.cc +++ b/libs/pbd/system_exec.cc @@ -215,8 +215,11 @@ SystemExec::SystemExec (std::string command, const std::map s // ...but always quote all args for (int i = 1; argp[i]; ++i) { std::string tmp (argp[i]); - while (tmp.find("\"") != std::string::npos) - tmp.replace(tmp.find("\""), 1, "\\\""); + size_t start_pos = 0; + while ((start_pos = tmp.find("\"", start_pos)) != std::string::npos) { + tmp.replace (start_pos, 1, "\\\""); + start_pos += 2; + } wa += " \""; wa += tmp; wa += '"';