Skip to content

Commit 57f0263

Browse files
mcourteauxqiin2333
authored andcommitted
fix(launch): Fix several launch failure conditions (exceptions thrown in child.wait, and boost::split_unix) (LizardByte#4390)
1 parent b3a0294 commit 57f0263

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

src/nvhttp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ using json = nlohmann::json;
4343
using namespace std::literals;
4444
namespace nvhttp {
4545

46+
static constexpr std::string_view EMPTY_PROPERTY_TREE_ERROR_MSG = "Property tree is empty. Probably, control flow got interrupted by an unexpected C++ exception. This is a bug in Sunshine. Moonlight-qt will report Malformed XML (missing root element)."sv;
47+
4648
namespace fs = std::filesystem;
4749
namespace pt = boost::property_tree;
4850

@@ -1226,6 +1228,10 @@ namespace nvhttp {
12261228
auto g = util::fail_guard([&]() {
12271229
std::ostringstream data;
12281230

1231+
if (tree.empty()) {
1232+
BOOST_LOG(error) << EMPTY_PROPERTY_TREE_ERROR_MSG;
1233+
}
1234+
12291235
pt::write_xml(data, tree);
12301236
response->write(data.str());
12311237
response->close_connection_after_response = true;
@@ -1345,6 +1351,10 @@ namespace nvhttp {
13451351
auto g = util::fail_guard([&]() {
13461352
std::ostringstream data;
13471353

1354+
if (tree.empty()) {
1355+
BOOST_LOG(error) << EMPTY_PROPERTY_TREE_ERROR_MSG;
1356+
}
1357+
13481358
pt::write_xml(data, tree);
13491359
response->write(data.str());
13501360
response->close_connection_after_response = true;

src/process.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <boost/program_options/parsers.hpp>
1919
#include <boost/property_tree/json_parser.hpp>
2020
#include <boost/property_tree/ptree.hpp>
21-
21+
#include <boost/token_functions.hpp>
2222
#include <openssl/evp.h>
2323
#include <openssl/sha.h>
2424

@@ -109,11 +109,17 @@ namespace proc {
109109
boost::filesystem::path
110110
find_working_directory(const std::string &cmd, boost::process::v1::environment &env) {
111111
// Parse the raw command string into parts to get the actual command portion
112+
std::vector<std::string> parts;
113+
try {
112114
#ifdef _WIN32
113-
auto parts = boost::program_options::split_winmain(cmd);
115+
parts = boost::program_options::split_winmain(cmd);
114116
#else
115-
auto parts = boost::program_options::split_unix(cmd);
117+
parts = boost::program_options::split_unix(cmd);
116118
#endif
119+
} catch (boost::escaped_list_error &err) {
120+
BOOST_LOG(error) << "Boost failed to parse command ["sv << cmd << "] because " << err.what();
121+
return boost::filesystem::path();
122+
}
117123
if (parts.empty()) {
118124
BOOST_LOG(error) << "Unable to parse command: "sv << cmd;
119125
return boost::filesystem::path();
@@ -232,10 +238,14 @@ namespace proc {
232238
}
233239
}
234240

235-
child.wait();
241+
child.wait(ec);
242+
if (ec) {
243+
BOOST_LOG(error) << '[' << cmd.do_cmd << "] wait failed with error code ["sv << ec << ']';
244+
return -1;
245+
}
236246
auto ret = child.exit_code();
237-
if (ret != 0 && ec != std::errc::permission_denied) {
238-
BOOST_LOG(error) << '[' << cmd.do_cmd << "] failed with code ["sv << ret << ']';
247+
if (ret != 0) {
248+
BOOST_LOG(error) << '[' << cmd.do_cmd << "] exited with code ["sv << ret << ']';
239249
return -1;
240250
}
241251
}

src_assets/common/assets/box.png

-146 KB
Loading

0 commit comments

Comments
 (0)