Skip to content

Raise dpkt error instead of IndexError on truncated SSL2 and BGP EVPN records - #683

Closed
eeshsaxena wants to merge 1 commit into
kbandla:masterfrom
eeshsaxena:fix/ssl2-bgp-evpn-truncated-indexerror
Closed

eeshsaxena wants to merge 1 commit into
kbandla:masterfrom
eeshsaxena:fix/ssl2-bgp-evpn-truncated-indexerror

Conversation

@eeshsaxena

Copy link
Copy Markdown

Two more truncated-packet paths (same class as #682) that leak a raw IndexError instead of a dpkt error.

SSL2

SSL2.unpack reads the padding-length byte in the 3-byte header form with compat_ord(self.data[0]). A record that stops after the 2-byte length field leaves self.data empty:

import dpkt
dpkt.ssl.SSL2(b'\x00\x01')   # IndexError: index out of range

BGP EVPN

RouteEVPN.unpack reads the MAC and IP address length bytes with compat_ord(buf[0]) without checking the buffer:

dpkt.bgp.RouteEVPN(b'\xff\xff\xff\xff')   # IndexError: index out of range

Fix

Guard each read and raise dpkt.NeedData, consistent with the other truncated-packet handling in these modules.

Tests

Added test_ssl2_truncated_padding_length (ssl.py) and test_route_evpn_truncated (bgp.py), covering the SSL2 padding byte and both the MAC (type 2) and IP (type != 1) length reads. They fail with IndexError before this change and pass after. ssl.py and bgp.py tests pass (62).

SSL2.unpack read self.data[0] for the padding length in the 3-byte header
form, and RouteEVPN.unpack read buf[0] for the MAC/IP address length. A
truncated record left those buffers empty, so parsing raised a raw
IndexError instead of dpkt.NeedData like the other truncated-packet paths.

Guard each read and raise NeedData. Add regression tests.
@eeshsaxena

Copy link
Copy Markdown
Author

Closing this to clear out my older open PRs. Nothing wrong with the change on my side, I am just tidying up a backlog. If it is still useful to you, say so and I will reopen it and rebase it on current main.

@eeshsaxena eeshsaxena closed this Sep 6, 2026
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