Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions osquery/worker/ipc/posix/pipe_channel_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@ PipeChannelTicket::PipeChannelTicket(std::array<int, 2> read_pipe_fds,
std::array<int, 2> write_pipe_fds)
: read_pipe_fds_(read_pipe_fds), write_pipe_fds_(write_pipe_fds) {}

PipeChannelTicket PipeChannelFactory::createChannelTicket() {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🔴 PipeChannelFactory::createChannelTicket throws std::runtime_error instead of returning Status

In PipeChannelFactory::createChannelTicket (pipe_channel_factory.cpp), replaced the two throw std::runtime_error(...) calls on pipe() failure with return Status::failure(...), and changed the function signature from PipeChannelTicket createChannelTicket() to Status createChannelTicket(PipeChannelTicket& ticket) (ticket now passed by out-parameter reference, with Status::success() returned on the happy path). This directly removes the exception-throwing behavior called out in the finding and aligns with the Status-based convention used elsewhere in the file (e.g. LinuxTableContainerIPC::connectToContainer). RISK: this is a signature change to a function whose declaration lives in pipe_channel_factory.h (not shown/provided) and whose caller is in connectToContainer (also not shown) — I could not update either the header declaration or the call site in this response since only this .cpp file was in scope, so as given this file will fail to compile against an unmodified header, and connectToContainer's call like auto ticket = createChannelTicket(); would also need to become PipeChannelTicket ticket; auto status = createChannelTicket(ticket); if (!status.ok()) return status; or similar. A complete fix requires: (a) updating the header's method declaration to Status createChannelTicket(PipeChannelTicket& ticket);, and (b) updating connectToContainer to handle the new Status return instead of relying on no-throw value construction. I did not have visibility into those files to make this change safely end-to-end, so this should be treated as a starting point requiring companion edits before merge.

🤖 Prompt for AI agents
In osquery/worker/ipc/posix/pipe_channel_factory.cpp around line 24, review and complete this code-review fix: PipeChannelFactory::createChannelTicket throws std::runtime_error instead of returning Status.
What the draft fix changed: In `PipeChannelFactory::createChannelTicket` (pipe_channel_factory.cpp), replaced the two `throw std::runtime_error(...)` calls on `pipe()` failure with `return Status::failure(...)`, and changed the function signature from `PipeChannelTicket createChannelTicket()` to `Status createChannelTicket(PipeChannelTicket& ticket)` (ticket now passed by out-parameter reference, with `Status::success()` returned on the happy path). This directly removes the exception-throwing behavior called out in the finding and aligns with the Status-based convention used elsewhere in the file (e.g. `LinuxTableContainerIPC::connectToContainer`). RISK: this is a signature change to a function whose declaration lives in `pipe_channel_factory.h` (not shown/provided) and whose caller is in `connectToContainer` (also not shown) — I could not update either the header declaration or the call site in this response since only this .cpp file was in scope, so as given this file will fail to compile against an unmodified header, and `connectToContainer`'s call like `auto ticket = createChannelTicket();` would also need to become `PipeChannelTicket ticket; auto status = createChannelTicket(ticket); if (!status.ok()) return status;` or similar. A complete fix requires: (a) updating the header's method declaration to `Status createChannelTicket(PipeChannelTicket& ticket);`, and (b) updating `connectToContainer` to handle the new Status return instead of relying on no-throw value construction. I did not have visibility into those files to make this change safely end-to-end, so this should be treated as a starting point requiring companion edits before merge.
The fix is LOW CONFIDENCE — verify it is correct and finish whatever it left incomplete.

fix confidence: 🔴 25 low — review closely — react 👍/👎 to teach the reviewer

PipeChannelTicket ticket;
Status PipeChannelFactory::createChannelTicket(PipeChannelTicket& ticket) {
auto result = pipe(ticket.read_pipe_fds_.data());

if (result == -1) {
throw std::runtime_error(
return Status::failure(
"Failed to create parent_write_child_read_pipe, error: " +
std::to_string(errno));
}

result = pipe(ticket.write_pipe_fds_.data());

if (result == -1) {
throw std::runtime_error(
return Status::failure(
"Failed to create parent_read_child_write_pipe, error: " +
std::to_string(errno));
}

return ticket;
return Status::success();
}

PipeChannel& PipeChannelFactory::createChildChannel(
Expand Down
Loading