提交 47e1a5ba 编辑于 作者: Teddy Reed's avatar Teddy Reed 提交者: GitHub
浏览文件

Use noexcept boost::filesystem overloads (#2195)

上级 3472b7cc
显示 18 个添加9 个删除
+18 -9
......@@ -18,6 +18,7 @@
#include <osquery/logger.h>
namespace fs = boost::filesystem;
namespace errc = boost::system::errc;
namespace osquery {
......@@ -38,7 +39,9 @@ REGISTER(FilesystemConfigPlugin, "config", "filesystem");
Status FilesystemConfigPlugin::genConfig(
std::map<std::string, std::string>& config) {
if (!fs::is_regular_file(FLAGS_config_path)) {
boost::system::error_code ec;
if (!fs::is_regular_file(FLAGS_config_path, ec) ||
ec.value() != errc::success) {
return Status(1, "config file does not exist: " + FLAGS_config_path);
}
......@@ -60,7 +63,8 @@ Status FilesystemConfigPlugin::genConfig(
Status FilesystemConfigPlugin::genPack(const std::string& name,
const std::string& value,
std::string& pack) {
if (!fs::is_regular_file(value)) {
boost::system::error_code ec;
if (!fs::is_regular_file(value, ec) || ec.value() != errc::success) {
return Status(1, value + " is not a valid path");
}
return readFile(value, pack);
......
......@@ -349,7 +349,8 @@ void WatcherRunner::createWorker() {
}
// Get the complete path of the osquery process binary.
auto exec_path = fs::system_complete(fs::path(qd[0]["path"]));
boost::system::error_code ec;
auto exec_path = fs::system_complete(fs::path(qd[0]["path"]), ec);
if (!safePermissions(
exec_path.parent_path().string(), exec_path.string(), true)) {
// osqueryd binary has become unsafe.
......@@ -385,7 +386,8 @@ bool WatcherRunner::createExtension(const std::string& extension) {
}
// Check the path to the previously-discovered extension binary.
auto exec_path = fs::system_complete(fs::path(extension));
boost::system::error_code ec;
auto exec_path = fs::system_complete(fs::path(extension), ec);
if (!safePermissions(
exec_path.parent_path().string(), exec_path.string(), true)) {
// Extension binary has become unsafe.
......
......@@ -296,7 +296,8 @@ inline void replaceGlobWildcards(std::string& pattern, GlobLimits limits) {
(pattern.size() > 3 && pattern[1] != ':' &&
pattern[2] != '\\' && pattern[2] != '/'))) &&
pattern[0] != '~') {
pattern = (fs::initial_path() / pattern).make_preferred().string();
boost::system::error_code ec;
pattern = (fs::current_path(ec) / pattern).make_preferred().string();
}
auto base =
......@@ -443,8 +444,9 @@ const std::string& osqueryHomeDirectory() {
(fs::path(*home_directory) / ".osquery").make_preferred().string();
} else {
// Fail over to a temporary directory (used for the shell).
homedir =
(fs::temp_directory_path() / "osquery").make_preferred().string();
boost::system::error_code ec;
auto temp = fs::temp_directory_path(ec);
homedir = (temp / "osquery").make_preferred().string();
}
}
......
......@@ -1046,7 +1046,7 @@ std::vector<std::string> platformGlob(const std::string &find_path) {
// going to append the component to the previous valid path and append
// the new path to the list
boost::system::error_code ec;
if (fs::exists(valid_path / component) &&
if (fs::exists(valid_path / component, ec) &&
ec.value() == errc::success) {
tmp_valid_paths.push_back(valid_path / component);
}
......@@ -1174,7 +1174,8 @@ static bool dirPathsAreEqual(const fs::path &dir1, const fs::path &dir2) {
}
Status platformIsTmpDir(const fs::path &dir) {
if (!dirPathsAreEqual(dir, fs::temp_directory_path())) {
boost::system::error_code ec;
if (!dirPathsAreEqual(dir, fs::temp_directory_path(ec))) {
return Status(1, "Not temp directory");
}
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册