Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
pront committed Mar 7, 2025
1 parent a29b38f commit 6c84d8b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/sources/host_metrics/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ enum TcpError {
InvalidTcpState { state: u8 },
#[snafu(display("Received an error message from netlink; code: {code}"))]
NetlinkMsgError { code: i32 },
#[snafu(display("Invalid message length: {length}"))]
InvalidLength { length: usize },
}

#[repr(u8)]
Expand Down Expand Up @@ -145,11 +147,15 @@ fn parse_netlink_messages(
while offset < buffer.len() {
let remaining_bytes = &buffer[offset..];
if remaining_bytes.len() < 4 {
// Still treat this as an error since we can't even read the length
return Err(TcpError::TruncatedMessage);

Check failure on line 151 in src/sources/host_metrics/tcp.rs

View workflow job for this annotation

GitHub Actions / Checks

no variant or associated item named `TruncatedMessage` found for enum `sources::host_metrics::tcp::TcpError` in the current scope
}

let length = NativeEndian::read_u32(&remaining_bytes[0..4]) as usize;
if length < 4 || length > remaining_bytes.len() {
if length == 0 {
break; // Restore original behavior: treat as end of buffer
}
if length > remaining_bytes.len() {
return Err(TcpError::InvalidLength { length });
}

Expand Down

0 comments on commit 6c84d8b

Please sign in to comment.