Check socksaddr domain is valid

This commit is contained in:
世界 2022-09-13 19:50:00 +08:00
parent 27ddefbb89
commit a606585cf7
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 8 additions and 3 deletions

View file

@ -40,7 +40,7 @@ func (ap Socksaddr) Unwrap() Socksaddr {
}
func (ap Socksaddr) IsFqdn() bool {
return !ap.Addr.IsValid() && ap.Fqdn != ""
return !ap.Addr.IsValid() && IsDomainName(ap.Fqdn)
}
func (ap Socksaddr) IsValid() bool {

View file

@ -0,0 +1,6 @@
package metadata
import _ "unsafe" // for linkname
//go:linkname IsDomainName net.isDomainName
func IsDomainName(domain string) bool

View file

@ -53,8 +53,8 @@ func (c *ClientConn) Write(p []byte) (n int, err error) {
}
func (c *ClientConn) WriteBuffer(buffer *buf.Buffer) error {
defer buffer.Release()
if c.headerWritten {
defer buffer.Release()
return common.Error(c.Conn.Write(buffer.Bytes()))
}
err := ClientHandshakeBuffer(c.Conn, c.key, c.destination, buffer)
@ -105,7 +105,6 @@ func (c *ClientPacketConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
}
func (c *ClientPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
defer buffer.Release()
if !c.headerWritten {
err := ClientHandshakePacket(c.Conn, c.key, destination, buffer)
c.headerWritten = true