Skip to content

Commit

Permalink
config tool / installer fix. Proper escaping of command in exec() sub…
Browse files Browse the repository at this point in the history
…routine.
  • Loading branch information
cbuchner1 committed Jun 10, 2016
1 parent e8da7d3 commit 3de6a8a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tools/config_tool/config_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ using namespace std;

// execute a command and return its output
wstring exec(const wstring &cmd) {

// escape the command to run in double quotes
// and send it to a command shell
wchar_t tmp[1024];
wsprintf(tmp, L"cmd.exe /S /C \"%s\"", cmd.c_str());

wchar_t buffer[128];
wstring result = L"";
shared_ptr<FILE> pipe(_wpopen(cmd.c_str(), L"r"), _pclose);
shared_ptr<FILE> pipe(_wpopen(tmp, L"r"), _pclose);
if (!pipe) throw runtime_error("popen() failed!");
while (!feof(pipe.get())) {
if (fgetws(buffer, 128, pipe.get()) != NULL)
Expand Down

0 comments on commit 3de6a8a

Please sign in to comment.