fix(v2): parse AF_UNIX addresses; add criterion benches - #24
Open
pigri wants to merge 3 commits into
Open
Conversation
The address block was consumed twice: once by a dedicated
address_family == Unix pre-read, then again by the address match that
follows. The second read could never be satisfied, so the length guard
in front of it turned every AF_UNIX v2 header into UnexpectedEof. The
pre-read also skipped any TLVs following a Unix address.
Drop the pre-read. The length >= 216 check it carried is preserved by
the checked_sub below it, which raises the same
InsufficientLengthSpecified { given, needs: 216 }, and TLVs now go
through the same extension loop as every other address family.
Covered by parse tests for the plain, with-TLV and short-length cases,
plus an encode/parse round-trip.
One parse per accepted connection and one encode per upstream connection, so both are worth tracking: parse and encode for v1 tcp4 / tcp6 / unknown and v2 inet / inet6 / inet+TLVs, the non-PROXY rejection path, and a round-trip.
clippy::byte_char_slices, new since this file was last linted, rejects the char-array form. Same bytes, no behaviour change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AF_UNIX v2 headers could never parse
version2::parseconsumed the 216-byte address block twice — once in adedicated
address_family == Unixpre-read, then again in the addressmatch. The second read could not be satisfied, so theensure!(remaining >= address_len)in front of it turned every AF_UNIXv2 header into
UnexpectedEof. The pre-read also skipped any TLVs thatfollowed a Unix address (an old
TODO: Support TLVs).The fix drops the pre-read. The
length >= 216check it carried is notlost — the
checked_subbelow raises the identicalInsufficientLengthSpecified { given, needs: 216 }— and TLVs now flowthrough the same extension loop as every other address family.
Tests added (each verified to fail with the bug re-introduced):
parse_tests::test_unix— a plain AF_UNIX header parsesparse_tests::test_unix_with_tlv— trailing TLVs are parsed, not skippedparse_tests::test_unix_length_too_short— a length below 216 is refusedencode_tests::test_unix_roundtrip— encode → parse round-tripCriterion benches
One parse per accepted connection and one encode per upstream connection,
so both are worth tracking. Covers v1 tcp4/tcp6/unknown, v2
inet/inet6/inet+TLVs, the non-PROXY rejection path, and a round-trip.
Reference numbers on the current code: v2 inet parse 59 ns, v1 tcp4 parse
131 ns, v2 inet encode 71 ns, non-PROXY rejection 12 ns.