No longer accept short messages #1656
Closed
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.
At the moment, the code for unpacking RRs (mostly in the autogenerated code) is peppered with chunks of
off == len(msg)checks which return with a nil error.As far as I understand, this is a workaround for parsing messages with an rdlength of zero. This mostly works due to the
noRdatacheck inUnpackRRWithHeader.Removing these checks reveals that
TestNoRdataUnpackdoes not actually produce zero-rdlength messages for a good number of rrtypes, so thenoRdataearly return does not trigger. Theseoff == len(msg)clauses peppered everywhere cause parsing to instead succeed at the boundaries of arbitrary elements of a resource record, with the zero values assigned to the rest of the messages.This means that malformed RRs which are too short, but happen to end at the right byte boundary, will be considered valid, with any remaining fields being kept as the zero value.
In fact, even a nil buffer would be parsed as a "valid" RR by
dns.UnpackRR(nil, 0), producing this RR:This PR removes all of these checks while keeping functionality for real zero-rdlength RRs.
The malformed messages described above will no longer be considered valid.
TestNoRdataUnpackhas been updated to manually adjust the RRs to produce actual zero-rdlength messages.