File tree Expand file tree Collapse file tree 2 files changed +10
-13
lines changed
Expand file tree Collapse file tree 2 files changed +10
-13
lines changed Original file line number Diff line number Diff line change 11package mysql
22
33import (
4- "crypto/rand"
54 "crypto/sha1"
65 "encoding/binary"
76 "fmt"
87 "io"
8+ "math/rand"
99 "runtime"
10+ "time"
1011 "unicode/utf8"
1112)
1213
@@ -45,20 +46,16 @@ func CalcPassword(scramble, password []byte) []byte {
4546 return scramble
4647}
4748
48- func RandomBuf (size int ) ( []byte , error ) {
49+ func RandomBuf (size int ) []byte {
4950 buf := make ([]byte , size )
50-
51- if _ , err := io .ReadFull (rand .Reader , buf ); err != nil {
52- return nil , err
53- }
54-
55- // avoid to generate '\0'
56- for i , b := range buf {
57- if uint8 (b ) == 0 {
58- buf [i ] = '0'
51+ rand .Seed (time .Now ().UTC ().UnixNano ())
52+ for i := 0 ; i < size ; i ++ {
53+ buf [i ] = byte (rand .Intn (127 ))
54+ if buf [i ] == 0 || buf [i ] == byte ('$' ) {
55+ buf [i ]++
5956 }
6057 }
61- return buf , nil
58+ return buf
6259}
6360
6461func LengthEncodedInt (b []byte ) (num uint64 , isNull bool , n int ) {
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ func (s *Server) newConn(co net.Conn) *Conn {
7373
7474 c .status = SERVER_STATUS_AUTOCOMMIT
7575
76- c .salt , _ = RandomBuf (20 )
76+ c .salt = RandomBuf (20 )
7777
7878 c .txConns = make (map [* Node ]* client.SqlConn )
7979
You can’t perform that action at this time.
0 commit comments