Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SOCKS5 UDP ASSOCIATE bind address (v1.11+) #75

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions protocol/socks/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
} else if authResponse.Method != socks5.AuthTypeNotRequired {
return socks5.Response{}, E.New("socks5: unsupported auth method: ", authResponse.Method)
}
if command == socks5.CommandUDPAssociate {
destination = M.SocksaddrFrom(netip.IPv4Unspecified(), 0)
}
err = socks5.WriteRequest(conn, socks5.Request{
Command: command,
Destination: destination,
Expand Down Expand Up @@ -120,7 +123,7 @@
//nolint:staticcheck
handler Handler,
handlerEx HandlerEx,
source M.Socksaddr, destination M.Socksaddr,

Check failure on line 126 in protocol/socks/handshake.go

View workflow job for this annotation

GitHub Actions / Build

SA4009: argument destination is overwritten before first use (staticcheck)
onClose N.CloseHandlerFunc,
) error {
version, err := reader.ReadByte()
Expand All @@ -145,7 +148,7 @@
}
return E.New("socks4: authentication failed, username=", request.Username)
}
destination = request.Destination

Check failure on line 151 in protocol/socks/handshake.go

View workflow job for this annotation

GitHub Actions / Build

SA4009(related information): assignment to destination (staticcheck)
if handlerEx != nil {
handlerEx.NewConnectionEx(auth.ContextWithUser(ctx, request.Username), NewLazyConn(conn, version), source, destination, onClose)
} else {
Expand Down Expand Up @@ -259,15 +262,16 @@
done := make(chan struct{})
go func() {
//nolint:staticcheck
innerError = handler.NewPacketConnection(ctx, associatePacketConn, M.Metadata{Protocol: "socks5", Source: source, Destination: destination})
innerError = handler.NewPacketConnection(ctx, associatePacketConn, M.Metadata{Protocol: "socks5", Source: source, Destination: M.SocksaddrFrom(netip.IPv4Unspecified(), 0)})
close(done)
}()
err = common.Error(io.Copy(io.Discard, conn))
associatePacketConn.Close()
<-done
return E.Errors(innerError, err)
} else {
handlerEx.NewPacketConnectionEx(ctx, NewLazyAssociatePacketConn(bufio.NewServerPacketConn(udpConn), destination, conn), source, destination, onClose)
destination = request.Destination
handlerEx.NewPacketConnectionEx(ctx, NewLazyAssociatePacketConn(bufio.NewServerPacketConn(udpConn), destination, conn), source, M.SocksaddrFrom(netip.IPv4Unspecified(), 0), onClose)
return nil
}
default:
Expand Down
Loading