From 69da43180e638518ed47424f2eba20cd25f2e093 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 26 Jul 2020 22:47:51 +0200 Subject: Fix some ignored return values. --- src/lib/cross_linux.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/lib/cross_linux.cc') diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc index 25fd3490e..28b8a4b41 100644 --- a/src/lib/cross_linux.cc +++ b/src/lib/cross_linux.cc @@ -113,7 +113,10 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) { string ffprobe = "ffprobe \"" + content.string() + "\" 2> \"" + out.string() + "\""; LOG_GENERAL (N_("Probing with %1"), ffprobe); - system (ffprobe.c_str ()); + int const r = system (ffprobe.c_str()); + if (r == -1 || (WIFEXITED(r) && WEXITSTATUS(r) != 0)) { + LOG_GENERAL (N_("Could not run ffprobe (system returned %1"), r); + } } list > @@ -378,7 +381,10 @@ unprivileged () cerr << "getresuid() failed.\n"; exit (EXIT_FAILURE); } - seteuid (ruid); + if (seteuid(ruid) == -1) { + cerr << "seteuid() failed.\n"; + exit (EXIT_FAILURE); + } } PrivilegeEscalator::~PrivilegeEscalator () -- cgit v1.2.3 From 16d50c8309bad5547bd07a3a6e78b404d490d93d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 26 Jul 2020 23:08:01 +0200 Subject: Better error handling with Linux privilege escalator. --- src/lib/cross_linux.cc | 7 ++++--- src/lib/exceptions.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src/lib/cross_linux.cc') diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc index 28b8a4b41..e17f188b9 100644 --- a/src/lib/cross_linux.cc +++ b/src/lib/cross_linux.cc @@ -379,11 +379,9 @@ unprivileged () uid_t ruid, euid, suid; if (getresuid(&ruid, &euid, &suid) == -1) { cerr << "getresuid() failed.\n"; - exit (EXIT_FAILURE); } if (seteuid(ruid) == -1) { cerr << "seteuid() failed.\n"; - exit (EXIT_FAILURE); } } @@ -394,7 +392,10 @@ PrivilegeEscalator::~PrivilegeEscalator () PrivilegeEscalator::PrivilegeEscalator () { - seteuid (0); + int const r = seteuid(0); + if (r < 0) { + throw PrivilegeError (String::compose("seteuid() call failed with %1", errno)); + } } boost::filesystem::path diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 98534bb32..05cda9659 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -369,4 +369,14 @@ private: std::string _message; int _number; }; + + +class PrivilegeError : public std::runtime_error +{ +public: + explicit PrivilegeError (std::string s) + : std::runtime_error (s) + {} +}; + #endif -- cgit v1.2.3