Report invalid DNS address early

This commit is contained in:
安容
2025-04-26 14:03:51 +08:00
committed by 世界
parent e528d425a1
commit 0f8bd01aad
6 changed files with 21 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
@@ -37,7 +38,9 @@ func NewTCP(ctx context.Context, logger log.ContextLogger, tag string, options o
return nil, err
}
serverAddr := options.DNSServerAddressOptions.Build()
if serverAddr.Port == 0 {
if !serverAddr.Addr.IsValid() {
return nil, E.New("invalid server address: ", serverAddr)
} else if serverAddr.Port == 0 {
serverAddr.Port = 53
}
return &TCPTransport{