diff --git a/openframe/openframe_token_refresher.cpp b/openframe/openframe_token_refresher.cpp index 6e3cf8def86..ac93603fc7a 100644 --- a/openframe/openframe_token_refresher.cpp +++ b/openframe/openframe_token_refresher.cpp @@ -1,12 +1,13 @@ #include "openframe_token_refresher.h" #include "openframe_authorization_manager_provider.h" +#include namespace osquery { OpenframeTokenRefresher::OpenframeTokenRefresher(std::shared_ptr extractor) : running_(false), extractor_(extractor) { if (!extractor_) { - throw std::runtime_error("Token extractor cannot be null"); + LOG(ERROR) << "Token extractor cannot be null; token refresher will be inert"; } } @@ -21,6 +22,11 @@ void OpenframeTokenRefresher::start() { return; } + if (!extractor_) { + LOG(ERROR) << "Cannot start token refresher: token extractor is null"; + return; + } + running_ = true; refresh_thread_ = std::thread([this]() { while (running_) { @@ -48,6 +54,11 @@ void OpenframeTokenRefresher::stop() { void OpenframeTokenRefresher::process() { try { + if (!extractor_) { + LOG(ERROR) << "Token extractor is null; skipping token refresh"; + return; + } + auto new_token = extractor_->extractToken(); if (new_token.empty()) { LOG(ERROR) << "Failed to extract new token - empty token received"; @@ -68,4 +79,4 @@ void OpenframeTokenRefresher::process() { } } -} // namespace osquery \ No newline at end of file +} // namespace osquery diff --git a/osquery/database/database.cpp b/osquery/database/database.cpp index 0d48b81c59a..dcc451ec20e 100644 --- a/osquery/database/database.cpp +++ b/osquery/database/database.cpp @@ -300,9 +300,12 @@ Status getDatabaseValue(const std::string& domain, ReadLock lock(kDatabaseReset); if (!kDBInitialized) { - throw std::runtime_error("Cannot get database value: " + key); + return Status(1, "Cannot get database value: " + key); } else { auto plugin = getDatabasePlugin(); + if (plugin == nullptr) { + return Status(1, "Cannot get database plugin for value: " + key); + } return plugin->get(domain, key, value); } } @@ -342,10 +345,13 @@ Status setDatabaseBatch(const std::string& domain, ReadLock lock(kDatabaseReset); if (!kDBInitialized) { - throw std::runtime_error("Cannot set database values"); + return Status(1, "Cannot set database values"); } auto plugin = getDatabasePlugin(); + if (plugin == nullptr) { + return Status(1, "Cannot get database plugin to set values"); + } return plugin->putBatch(domain, data); } @@ -370,9 +376,12 @@ Status deleteDatabaseValue(const std::string& domain, const std::string& key) { ReadLock lock(kDatabaseReset); if (!kDBInitialized) { - throw std::runtime_error("Cannot delete database value: " + key); + return Status(1, "Cannot delete database value: " + key); } else { auto plugin = getDatabasePlugin(); + if (plugin == nullptr) { + return Status(1, "Cannot get database plugin to delete value: " + key); + } return plugin->remove(domain, key); } } @@ -396,10 +405,14 @@ Status deleteDatabaseRange(const std::string& domain, ReadLock lock(kDatabaseReset); if (!kDBInitialized) { - throw std::runtime_error("Cannot delete database values: " + low + " - " + - high); + return Status(1, "Cannot delete database values: " + low + " - " + high); } else { auto plugin = getDatabasePlugin(); + if (plugin == nullptr) { + return Status(1, + "Cannot get database plugin to delete values: " + low + + " - " + high); + } return plugin->removeRange(domain, low, high); } } @@ -439,9 +452,12 @@ Status scanDatabaseKeys(const std::string& domain, ReadLock lock(kDatabaseReset); if (!kDBInitialized) { - throw std::runtime_error("Cannot scan database values: " + prefix); + return Status(1, "Cannot scan database values: " + prefix); } else { auto plugin = getDatabasePlugin(); + if (plugin == nullptr) { + return Status(1, "Cannot get database plugin to scan values: " + prefix); + } return plugin->scan(domain, keys, prefix, max); } }