common/wireaddr: Fix an out-of-bounds bug in the address parser#8325
Merged
rustyrussell merged 2 commits intoElementsProject:masterfrom Sep 22, 2025
Merged
common/wireaddr: Fix an out-of-bounds bug in the address parser#8325rustyrussell merged 2 commits intoElementsProject:masterfrom
rustyrussell merged 2 commits intoElementsProject:masterfrom
Conversation
Changelog-Fixed: In `struct wireaddr`, the `addr` buffer is defined with a length of DNS_ADDRLEN (255). When parsing a valid DNS name that is exactly 255 bytes long, the subsequent attempt to append a `NULL` terminator overruns the buffer and triggers an out-of-bounds error under UBSan. Fix this by removing the line that appends `NULL`. This change is safe because the preceding call to: `memset(&addr->addr, 0, sizeof(addr->addr))` already zeroes the entire buffer.
4 tasks
Author
|
This bug was discovered through the new fuzz test in #8324. |
Contributor
|
Note that this bug is triggerable from outside |
morehouse
reviewed
Jun 7, 2025
common/test/run-wireaddr.c
Outdated
| expect->u.unresolved.port = 1234; | ||
| assert(wireaddr_internal_eq(&addr, expect)); | ||
|
|
||
| const char raw_input[] = |
Contributor
There was a problem hiding this comment.
Should add a comment describing the test, and also the bug that was fixed.
common/test/run-wireaddr.c
Outdated
Comment on lines
+246
to
+250
| const u8 *crashing_input = tal_dup_arr(tmpctx, u8, (const u8*) raw_input, sizeof(raw_input) - 1, 0); | ||
| size_t crashing_input_len = tal_bytelen(crashing_input); | ||
|
|
||
| struct wireaddr_internal decoded_wa; | ||
| assert(fromwire_wireaddr_internal(&crashing_input, &crashing_input_len, &decoded_wa)); |
Contributor
There was a problem hiding this comment.
Can we improve the test to check the expected decoded values, as with the above tests?
Author
There was a problem hiding this comment.
Right, the readability could also use some improvements.
Add a test in `common/test/run-wireaddr.c` that reproduces the out-of-bounds error when the fix is not applied.
morehouse
approved these changes
Jun 11, 2025
4 tasks
rustyrussell
approved these changes
Sep 22, 2025
Contributor
rustyrussell
left a comment
There was a problem hiding this comment.
Ack c8000f2
Good catch!
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.
In
struct wireaddr, theaddrbuffer is defined with a length ofDNS_ADDRLEN(255). When parsing a valid DNS name that is exactly 255 bytes long, the subsequent attempt to append aNULLterminator overruns the buffer and triggers an out-of-bounds error under UBSan.Fix this bug and add a test to guard against it.
Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:
CC: @morehouse