From d94a0aea9a4fee5d99f8f526b7a0cb5726bfe995 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 11 May 2020 18:25:25 -0400 Subject: [PATCH] upgrade go-ident to fix parsing issue --- go.mod | 2 +- go.sum | 2 + irc/client.go | 6 +-- vendor/github.com/oragono/go-ident/client.go | 43 ++++++++++---------- vendor/modules.txt | 2 +- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 455fcf2c..83fd8bc0 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/onsi/ginkgo v1.12.0 // indirect github.com/onsi/gomega v1.9.0 // indirect github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0 - github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a + github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775 github.com/stretchr/testify v1.4.0 // indirect github.com/tidwall/buntdb v1.1.2 github.com/toorop/go-dkim v0.0.0-20191019073156-897ad64a2eeb diff --git a/go.sum b/go.sum index 79889359..8aaa74ec 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,8 @@ github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0 h1:4qw57EiWD2M github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0/go.mod h1:+uesPRay9e5tW6zhw4CJkRV3QOEbbZIJcsuo9ZnC+hE= github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a h1:tZApUffT5QuX4XhJLz2KfBJT8JgdwjLUBWtvmRwgFu4= github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a/go.mod h1:r5Fk840a4eu3ii1kxGDNSJupQu9Z1UC1nfJOZZXC24c= +github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775 h1:AMAsAn/i4AgsmWQYdMoze9omwtHpbxrKuT+AT1LmhtI= +github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775/go.mod h1:r5Fk840a4eu3ii1kxGDNSJupQu9Z1UC1nfJOZZXC24c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/irc/client.go b/irc/client.go index 42845108..57d839d6 100644 --- a/irc/client.go +++ b/irc/client.go @@ -27,8 +27,8 @@ import ( ) const ( - // IdentTimeoutSeconds is how many seconds before our ident (username) check times out. - IdentTimeoutSeconds = 1.5 + // IdentTimeout is how long before our ident (username) check times out. + IdentTimeout = time.Second + 500*time.Millisecond IRCv3TimestampFormat = utils.IRCv3TimestampFormat ) @@ -483,7 +483,7 @@ func (client *Client) doIdentLookup(conn net.Conn) { clientPort := remoteTCPAddr.Port client.Notice(client.t("*** Looking up your username")) - resp, err := ident.Query(remoteTCPAddr.IP.String(), serverPort, clientPort, IdentTimeoutSeconds) + resp, err := ident.Query(remoteTCPAddr.IP.String(), serverPort, clientPort, IdentTimeout) if err == nil { err := client.SetNames(resp.Identifier, "", true) if err == nil { diff --git a/vendor/github.com/oragono/go-ident/client.go b/vendor/github.com/oragono/go-ident/client.go index 663da8a9..256bde7a 100644 --- a/vendor/github.com/oragono/go-ident/client.go +++ b/vendor/github.com/oragono/go-ident/client.go @@ -37,49 +37,46 @@ func (e ProtocolError) Error() string { } // Query makes an Ident query, if timeout is >0 the query is timed out after that many seconds. -func Query(ip string, portOnServer, portOnClient int, timeout float64) (Response, error) { - var ( - conn net.Conn - err error - fields []string - r *bufio.Reader - resp string - ) - +func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (response Response, err error) { + var conn net.Conn if timeout > 0 { - conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), time.Duration(timeout)*time.Second) + conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), timeout) } else { conn, err = net.Dial("tcp", net.JoinHostPort(ip, "113")) } if err != nil { - return Response{}, err + return } // stop the ident read after seconds if timeout > 0 { - conn.SetDeadline(time.Now().Add(time.Second * time.Duration(timeout))) + conn.SetDeadline(time.Now().Add(timeout)) } _, err = conn.Write([]byte(fmt.Sprintf("%d, %d", portOnClient, portOnServer) + "\r\n")) if err != nil { - return Response{}, err + return } - r = bufio.NewReader(conn) - resp, err = r.ReadString('\n') + r := bufio.NewReaderSize(conn, 1024) + respBytes, err := r.ReadSlice('\n') if err != nil { - return Response{}, err + return } + resp := string(respBytes) - fields = strings.SplitN(strings.TrimSpace(resp), " : ", 4) + fields := strings.SplitN(resp, ":", 4) if len(fields) < 3 { - return Response{}, ProtocolError{resp} + return response, ProtocolError{resp} + } + for i, field := range fields { + fields[i] = strings.TrimSpace(field) } switch fields[1] { case "USERID": if len(fields) != 4 { - return Response{}, ProtocolError{resp} + return response, ProtocolError{resp} } var os, charset string @@ -99,10 +96,12 @@ func Query(ip string, portOnServer, portOnClient int, timeout float64) (Response }, nil case "ERROR": if len(fields) != 3 { - return Response{}, ProtocolError{resp} + return response, ProtocolError{resp} } - return Response{}, ResponseError{fields[2]} + return response, ResponseError{fields[2]} + default: + err = ProtocolError{resp} } - return Response{}, err + return } diff --git a/vendor/modules.txt b/vendor/modules.txt index 1afed2a7..d829c119 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -30,7 +30,7 @@ github.com/goshuirc/irc-go/ircmsg # github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0 ## explicit github.com/oragono/confusables -# github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a +# github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775 ## explicit github.com/oragono/go-ident # github.com/stretchr/testify v1.4.0