Repository navigation
Resolv: build DNS wire messages as binary strings - #163
Open
TheRealAlexxx wants to merge 1 commit into
Open
TheRealAlexxx wants to merge 1 commit into
TheRealAlexxx wants to merge 1 commit into
Conversation
Fixes [Bug #19697]. `Resolv::DNS::MessageEncoder` accumulates the encoded packet in a UTF-8 buffer. When a query name contains non-ASCII characters, such as an internationalized domain name, the buffer becomes a UTF-8 string holding non-ASCII bytes, and binary writes into it start failing: assigning the request id in `ConnectedUDP#sender` (`request[0,2] = ...`) raises `Encoding::CompatibilityError` (incompatible character encodings: UTF-8 and ASCII-8BIT), so resolving such a name crashes before any packet is sent. The same hazard exists mid-encode, where `put_length16` backpatches a packed length into the buffer after writing a name. The wire format is bytes, so keep the buffer binary throughout: start it as ASCII-8BIT and append the binary form of byte strings, labels and character-strings. (An empty buffer adopts the encoding of the first string appended to it, so the initial conversion alone is not enough.) `Message#encode` now consistently returns an ASCII-8BIT string, matching what the socket layer and `Message.decode` already work with. The new test resolves an internationalized domain name against a stub DNS server; without the change it raises `Encoding::CompatibilityError` in `ConnectedUDP#sender`.
This branch has not been deployed
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.
Resolv: build DNS wire messages as binary strings
Fixes [Bug #19697].
Resolv::DNS::MessageEncoderaccumulates the encoded packet in a UTF-8 buffer. When a query name contains non-ASCII characters, such as an internationalized domain name, the buffer becomes a UTF-8 string holding non-ASCII bytes, and binary writes into it start failing: assigning the request id inConnectedUDP#sender(request[0,2] = ...) raisesEncoding::CompatibilityError(incompatible character encodings: UTF-8 and ASCII-8BIT), so resolving such a name crashes before any packet is sent. The same hazard exists mid-encode, whereput_length16backpatches a packed length into the buffer after writing a name.The wire format is bytes, so keep the buffer binary throughout: start it as ASCII-8BIT and append the binary form of byte strings, labels and character-strings. (An empty buffer adopts the encoding of the first string appended to it, so the initial conversion alone is not enough.)
Message#encodenow consistently returns an ASCII-8BIT string, matching what the socket layer andMessage.decodealready work with.The new test resolves an internationalized domain name against a stub DNS server; without the change it raises
Encoding::CompatibilityErrorinConnectedUDP#sender.