Skip to content

nstun: add a bounds-checked reader for IP parsing - #366

Open
agusgarcia3007 wants to merge 1 commit into
google:masterfrom
agusgarcia3007:nstun-bounds-checked-reader
Open

agusgarcia3007 wants to merge 1 commit into
google:masterfrom
agusgarcia3007:nstun-bounds-checked-reader

Conversation

@agusgarcia3007

Copy link
Copy Markdown

This is the first part of #309.

It adds a small ByteReader on top of std::span and uses it in the IPv4
and IPv6 receive paths. The IPv6 extension-header walk moves into
ipparse.cc so it can be tested on its own, without the rest of nstun.

The set of accepted and rejected packets is the same as before. The checks
are unchanged, but the pointer and the remaining length are now one object
and cannot drift apart.

Tests:

  • make on Debian bookworm with gcc 12 and -Wall -Wextra -Werror
  • tests/nstun_ipparse_test (new)
  • the other nstun unit tests still pass

I will send the libFuzzer targets in a separate PR, as suggested in the
issue.

@google-cla

google-cla Bot commented Oct 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Move the IPv6 extension-header walk into ipparse.cc and use a small
ByteReader for the IPv4 and IPv6 receive paths. The checks are the same,
but the pointer and remaining length are now one object.

Add tests for truncated extension headers, oversized lengths, fragments,
and the chain depth limit.
@agusgarcia3007
agusgarcia3007 force-pushed the nstun-bounds-checked-reader branch from 84a2e1b to 1e6a830 Compare October 19, 2026 21:55

This branch has not been deployed

No deployments
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