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
5 changes: 3 additions & 2 deletions osquery/tables/system/linux/apt_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Status parseAptSourceLine(const std::string& input_line,

apt_source.base_uri = tokens[offset];
// Cannot have trailing slashes
while (apt_source.base_uri.back() == '/') {
while (!apt_source.base_uri.empty() && apt_source.base_uri.back() == '/') {
apt_source.base_uri.pop_back();
}

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.

🦩 🟠 apt_sources.cpp back()-on-empty-string risk when parsing base_uri trailing slashes

In parseAptSourceLine, the trailing-slash trimming loop on apt_source.base_uri now checks !apt_source.base_uri.empty() before calling .back(), preventing undefined behavior when the URI is all slashes.

πŸ€– Prompt for AI agents
In osquery/tables/system/linux/apt_sources.cpp around line 89, review and complete this code-review fix: apt_sources.cpp back()-on-empty-string risk when parsing base_uri trailing slashes.
What the draft fix changed: In `parseAptSourceLine`, the trailing-slash trimming loop on `apt_source.base_uri` now checks `!apt_source.base_uri.empty()` before calling `.back()`, preventing undefined behavior when the URI is all slashes.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 95 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer


Expand Down Expand Up @@ -264,7 +264,7 @@ Status parseDeb822Block(const std::string& input_block,
continue;
}
// Cannot have trailing slashes
while (uri.back() == '/') {
while (!uri.empty() && uri.back() == '/') {
uri.pop_back();
}
uris.push_back(uri);
Comment on lines 264 to 270

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.

🦩 🟠 Same unchecked .back() pattern repeated in parseDeb822Block URI trimming

In parseDeb822Block, the trailing-slash trimming loop on uri (inside the key == "uris" branch) now checks !uri.empty() before calling .back(), preventing undefined behavior for malformed all-slash URIs from DEB822 sources.

πŸ€– Prompt for AI agents
In osquery/tables/system/linux/apt_sources.cpp around line 253, review and complete this code-review fix: Same unchecked .back() pattern repeated in parseDeb822Block URI trimming.
What the draft fix changed: In `parseDeb822Block`, the trailing-slash trimming loop on `uri` (inside the `key == "uris"` branch) now checks `!uri.empty()` before calling `.back()`, preventing undefined behavior for malformed all-slash URIs from DEB822 sources.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 95 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Expand Down Expand Up @@ -400,3 +400,4 @@ QueryData genAptSrcs(QueryContext& context) {
}
} // namespace tables
} // namespace osquery