MtProtoKit: fix SOCKS5 proxy IPv6 connect sent garbage address#179
Open
mvsrcdst wants to merge 1 commit into
Open
MtProtoKit: fix SOCKS5 proxy IPv6 connect sent garbage address#179mvsrcdst wants to merge 1 commit into
mvsrcdst wants to merge 1 commit into
Conversation
3 tasks
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.
Problem
Users on SOCKS5 proxy fail to connect when the resolved DC address is IPv6 connection spins forever, never drops or errors out.
Root cause:
requestSocksConnectioninMTTcpConnection.mhardcodedreq.AddrType = 1(IPv4) and nevern value. When _scheme.address.ipis an IPv6 literal,inet_atonfails silently, leavingreq.DestAddr.IPv4holding uninitialized stack garbage which still got sent to the proxy tagged as can't route the connect to a real address, so it just hangs indefinitely instead of failing.Depends on which DC address the client resolves to (IPv4 vs IPv6), not on whether the proxy server itself supports IPv6.
Fix
Detect IPv4 vs IPv6 properly before building the connect request, mirroring the pattern already used in -start for _socksIp/_mtpIp:
inet_atonsucceeds - IPv4 (ATYP=1)inet_pton(AF_INET6, ...)succeeds - IPv6 (ATYP=4)Impact
SOCKS5 proxy connections no longer hang indefinitely when the resolved DC address is IPv6.
Note
Upstream has PR TelegramMessenger#735 addressing this same issue, currently under discussion.
Part of tracking issue: #182
Testing