Repository navigation
fix(OSQUERY-002-2): CU-17tkuw5wp49 2 review findings across 2 files #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,29 +31,34 @@ const std::vector<std::tuple<std::string, std::string>> kKnownCgroupPrefixList{ | |
| {"/libpod-", "podman"}, | ||
| }; | ||
|
|
||
| std::string getProcUptimeContents() { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🦩 🔴 getProcUptimeContents / getSystemBootTime throw std::runtime_error in production osquery code In 🤖 Prompt for AI agentsfix confidence: 🟡 85 medium — react 👍/👎 to teach the reviewer |
||
| std::string uptime_contents; | ||
| Status getProcUptimeContents(std::string& uptime_contents) { | ||
| uptime_contents.clear(); | ||
|
|
||
| { | ||
| std::ifstream uptime_file(kProcUptimeFilePath.c_str(), std::ios::in); | ||
| if (!uptime_file) { | ||
| throw std::runtime_error("Failed to access the following path: " + | ||
| kProcUptimeFilePath); | ||
| return Status::failure("Failed to access the following path: " + | ||
| kProcUptimeFilePath); | ||
| } | ||
|
|
||
| std::getline(uptime_file, uptime_contents); | ||
| } | ||
|
|
||
| return uptime_contents; | ||
| return Status::success(); | ||
| } | ||
|
|
||
| std::uint64_t getSystemBootTime() { | ||
| Status getSystemBootTime(std::uint64_t& boot_time) { | ||
| auto current_time = std::time(nullptr); | ||
| auto uptime_contents = getProcUptimeContents(); | ||
|
|
||
| std::string uptime_contents; | ||
| auto status = getProcUptimeContents(uptime_contents); | ||
| if (!status.ok()) { | ||
| return status; | ||
| } | ||
|
|
||
| auto separator_index = uptime_contents.find('.'); | ||
| if (separator_index == std::string::npos) { | ||
| throw std::runtime_error("Invalid data read from " + kProcUptimeFilePath); | ||
| return Status::failure("Invalid data read from " + kProcUptimeFilePath); | ||
| } | ||
|
|
||
| auto string_uptime = uptime_contents.substr(0, separator_index); | ||
|
|
@@ -63,10 +68,11 @@ std::uint64_t getSystemBootTime() { | |
| std::strtoull(string_uptime.c_str(), &last_parsed_char, 10); | ||
| if (integer_uptime == 0 || last_parsed_char == nullptr || | ||
| *last_parsed_char != 0) { | ||
| throw std::runtime_error("Invalid data read from " + kProcUptimeFilePath); | ||
| return Status::failure("Invalid data read from " + kProcUptimeFilePath); | ||
| } | ||
|
|
||
| return current_time - integer_uptime; | ||
| boot_time = current_time - integer_uptime; | ||
| return Status::success(); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
@@ -131,7 +137,11 @@ TableRows BPFProcessEventsTable::generate(QueryContext& context) { | |
| TableRows row_list; | ||
| std::stringstream buffer; | ||
|
|
||
| auto system_boot_time = getSystemBootTime(); | ||
| std::uint64_t system_boot_time{0U}; | ||
| auto status = getSystemBootTime(system_boot_time); | ||
| if (!status.ok()) { | ||
| return row_list; | ||
| } | ||
|
|
||
| for (const auto& event : d->event_list) { | ||
| auto row = make_table_row(); | ||
|
|
@@ -214,4 +224,4 @@ TableRows BPFProcessEventsTable::generate(QueryContext& context) { | |
| return row_list; | ||
| } | ||
|
|
||
| } // namespace osquery | ||
| } // namespace osquery | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🦩 🔵 configureBPFMemoryLimitsHelper throws std::runtime_error instead of returning Status
Changed configureBPFMemoryLimitsHelper() in osquery/events/linux/bpf/setrlimit.cpp to return bool instead of throwing std::runtime_error on setrlimit() failure. Added a static bool setrlimit_succeeded captured by the std::call_once lambda invocation inside configureBPFMemoryLimits(), which now checks the result directly and returns Status::failure(...) with the original message instead of relying on catching an exception. The try/catch around std::call_once was removed since no exception is thrown anymore. This preserves the "call once" semantics and the externally observed Status::failure behavior for callers.
🤖 Prompt for AI agents
fix confidence: 🟡 85 medium — react 👍/👎 to teach the reviewer