Skip to content

Fix panic on malformed SFlow packets#1228

Open
mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
mohammadmseet-hue:fix-sflow-panic
Open

Fix panic on malformed SFlow packets#1228
mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
mohammadmseet-hue:fix-sflow-panic

Conversation

@mohammadmseet-hue
Copy link
Copy Markdown

Summary

Add bounds checking in SFlowDatagram.DecodeFromBytes before reading header fields to prevent panics on malformed packets.

Root cause: Chained assignments like data, s.X = data[4:], binary.BigEndian.Uint32(data[:4]) assume sufficient data remains. No minimum length check exists. Agent address length from the packet is used for slicing without validation.

Fix: Add minimum length check at entry, validate remaining data against agent address length + required header fields, and check data length before sample iteration.

Panics fixed: 5 (too short, truncated after version, IPv6 truncated, large sample count, bad agent type)

All existing tests pass.

Add bounds checking in SFlowDatagram.DecodeFromBytes before reading
header fields. The chained data/field assignments assumed sufficient
data length, causing slice bounds panics on truncated packets, short
agent addresses, and missing sample data.

Return an error instead of panicking when data is too short.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant