Skip to content

optim: remove useless return value for mysql.util.RandomBuf #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mysql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

/*
Expand Down Expand Up @@ -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 {
Expand All @@ -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)

Expand All @@ -82,15 +82,14 @@ func NewCustomizedConn(conn net.Conn, serverConf *Server, p CredentialProvider,
packetConn = packet.NewConn(conn)
}

salt, _ := RandomBuf(20)
c := &Conn{
Conn: packetConn,
serverConf: serverConf,
credentialProvider: p,
h: h,
connectionID: atomic.AddUint32(&baseConnID, 1),
stmts: make(map[uint32]*Stmt),
salt: salt,
salt: RandomBuf(20),
}
c.closed.Set(false)

Expand Down
6 changes: 1 addition & 5 deletions server/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down