diff --git a/mysql/util.go b/mysql/util.go index 1a86a6bc6..e8d436fa2 100644 --- a/mysql/util.go +++ b/mysql/util.go @@ -107,14 +107,14 @@ func AppendLengthEncodedInteger(b []byte, n uint64) []byte { byte(n>>32), byte(n>>40), byte(n>>48), byte(n>>56)) } -func RandomBuf(size int) ([]byte, error) { +func RandomBuf(size int) []byte { buf := make([]byte, size) mrand.Seed(time.Now().UTC().UnixNano()) min, max := 30, 127 for i := 0; i < size; i++ { buf[i] = byte(min + mrand.Intn(max-min)) } - return buf, nil + return buf } // FixedLengthInt: little endian diff --git a/server/conn.go b/server/conn.go index c42f1c328..92aa8fa8d 100644 --- a/server/conn.go +++ b/server/conn.go @@ -5,9 +5,10 @@ import ( "net" "sync/atomic" + "github.com/siddontang/go/sync2" + . "github.com/go-mysql-org/go-mysql/mysql" "github.com/go-mysql-org/go-mysql/packet" - "github.com/siddontang/go/sync2" ) /* @@ -45,7 +46,6 @@ var baseConnID uint32 = 10000 func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, error) { p := NewInMemoryProvider() p.AddUser(user, password) - salt, _ := RandomBuf(20) var packetConn *packet.Conn if defaultServer.tlsConfig != nil { @@ -61,7 +61,7 @@ func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, err h: h, connectionID: atomic.AddUint32(&baseConnID, 1), stmts: make(map[uint32]*Stmt), - salt: salt, + salt: RandomBuf(20), } c.closed.Set(false) @@ -82,7 +82,6 @@ func NewCustomizedConn(conn net.Conn, serverConf *Server, p CredentialProvider, packetConn = packet.NewConn(conn) } - salt, _ := RandomBuf(20) c := &Conn{ Conn: packetConn, serverConf: serverConf, @@ -90,7 +89,7 @@ func NewCustomizedConn(conn net.Conn, serverConf *Server, p CredentialProvider, h: h, connectionID: atomic.AddUint32(&baseConnID, 1), stmts: make(map[uint32]*Stmt), - salt: salt, + salt: RandomBuf(20), } c.closed.Set(false) diff --git a/server/resp.go b/server/resp.go index 35b742e9c..abe04c774 100644 --- a/server/resp.go +++ b/server/resp.go @@ -68,12 +68,8 @@ func (c *Conn) writeAuthSwitchRequest(newAuthPluginName string) error { data = append(data, EOF_HEADER) data = append(data, []byte(newAuthPluginName)...) data = append(data, 0x00) - rnd, err := RandomBuf(20) - if err != nil { - return err - } // new auth data - c.salt = rnd + c.salt = RandomBuf(20) data = append(data, c.salt...) // the online doc states it's a string.EOF, however, the actual MySQL server add a \NUL to the end, without it, the // official MySQL client will fail.