Skip to content

Commit b68a43f

Browse files
cty123yuhan6665
authored andcommitted
fix: correct the logic of converting SocksAddr into net.Destination.
1 parent 7aeca33 commit b68a43f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

common/singbridge/destination.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@ func ToNetwork(network string) net.Network {
1818
}
1919

2020
func ToDestination(socksaddr M.Socksaddr, network net.Network) net.Destination {
21+
// IsFqdn() implicitly checks if the domain name is valid
2122
if socksaddr.IsFqdn() {
2223
return net.Destination{
2324
Network: network,
2425
Address: net.DomainAddress(socksaddr.Fqdn),
2526
Port: net.Port(socksaddr.Port),
2627
}
27-
} else {
28+
}
29+
30+
// IsIP() implicitly checks if the IP address is valid
31+
if socksaddr.IsIP() {
2832
return net.Destination{
2933
Network: network,
3034
Address: net.IPAddress(socksaddr.Addr.AsSlice()),
3135
Port: net.Port(socksaddr.Port),
3236
}
3337
}
38+
39+
return net.Destination{}
3440
}
3541

3642
func ToSocksaddr(destination net.Destination) M.Socksaddr {

proxy/shadowsocks_2022/inbound_multi.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ func (i *MultiUserInbound) NewConnection(ctx context.Context, conn net.Conn, met
204204
})
205205
newError("tunnelling request to tcp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
206206
dispatcher := session.DispatcherFromContext(ctx)
207-
link, err := dispatcher.Dispatch(ctx, singbridge.ToDestination(metadata.Destination, net.Network_TCP))
207+
destination := singbridge.ToDestination(metadata.Destination, net.Network_TCP)
208+
if !destination.IsValid() {
209+
return newError("invalid destination")
210+
}
211+
212+
link, err := dispatcher.Dispatch(ctx, destination)
208213
if err != nil {
209214
return err
210215
}

0 commit comments

Comments
 (0)