Repository navigation
Bound the length in IRRd A<len> replies - #141
Merged
Merged
Conversation
The length announced in an "A<len>" reply comes straight from the IRR server. In the pipelined path malloc(togot + 2) wraps for a length near ULONG_MAX and the reply is copied into a tiny buffer. In the non-pipelined path togot is a signed long, so a large value goes negative and the copy runs with a huge size. Reject lengths above 256 MiB in both paths before allocating, and parse the non-pipelined length as unsigned before the check.
job
reviewed
Nov 19, 2026
| char *eon, *c; | ||
| long togot = strtoul(response + 1, &eon, 10); | ||
| char *recvbuffer = malloc(togot + 2); | ||
| unsigned long len = strtoul(response + 1, &eon, 10); |
Contributor
Author
There was a problem hiding this comment.
Good call, added in be82f3e for both paths: errno is cleared before strtoul and a range error is rejected along with the cap. make check still passes and both reply shapes still exit with the error.
Treat a strtoul range error as an invalid length in both paths.
Contributor
Author
|
Thanks for merging, and for the errno 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.
This bounds the length bgpq4 accepts from an IRRd
A<len>reply before allocating the receive buffer.malloc(togot + 2)wraps for a length nearULONG_MAX, and the reply is then copied into a tiny buffer.togotis a signedlong, so a large value goes negative and the copy runs with a huge size.Both paths now reject a length above 256 MiB with an error before allocating. The non-pipelined path parses the length as unsigned first. 256 MiB keeps the
int offsetin that path safe and leaves a lot of room for big AS-SET expansions, but I picked it, so change it to whatever you think fits.Testing:
make checkpasses. I also replayed both reply shapes from a local fake IRR server: main aborts, this branch exits with the error, and valid replies give the same output on both.