Skip to content

Commit

Permalink
[Enhancement]: Optimize insecure random number generation in function…
Browse files Browse the repository at this point in the history
… util/string.go:RandomString

close: #2696
Signed-off-by: true1064 <tangjingyu@oppo.com>
  • Loading branch information
true1064 committed Oct 23, 2023
1 parent 71cbf46 commit 8555c64
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions proto/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ func (p *Packet) GetOpMsg() (m string) {
m = "OpLcNodeScan"
case OpLcNodeSnapshotVerDel:
m = "OpLcNodeSnapshotVerDel"
case OpMetaReadDirOnly:
m = "OpMetaReadDirOnly"
default:
m = fmt.Sprintf("op:%v not found", p.Opcode)
}
Expand Down
3 changes: 2 additions & 1 deletion sdk/data/stream/stream_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ begin:
}
}
// try append write, get response
log.LogDebugf("action[streamer.write] doAppendWrite req %v FileOffset %v size %v", req.ExtentKey, req.FileOffset, req.Size)
log.LogDebugf("action[streamer.write] doAppendWrite req: ExtentKey(%v) FileOffset(%v) size(%v)",
req.ExtentKey, req.FileOffset, req.Size)
var status int32
// First, attempt sequential writes using neighboring extent keys. If the last extent has a different version,
// it indicates that the extent may have been fully utilized by the previous version.
Expand Down
10 changes: 5 additions & 5 deletions util/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package util

import (
"math/rand"
"crypto/rand"
"math/big"
"strings"
"time"
)

func SubString(sourceString string, begin, end int) string {
Expand Down Expand Up @@ -59,9 +59,9 @@ func RandomString(length int, seed RandomSeed) string {
runs := seed.Runes()
result := ""
for i := 0; i < length; i++ {
rand.Seed(time.Now().UnixNano())
randNumber := rand.Intn(len(runs))
result += string(runs[randNumber])
lenInt64 := int64(len(runs))
randNumber, _ := rand.Int(rand.Reader, big.NewInt(lenInt64))
result += string(runs[randNumber.Uint64()])
}
return result
}

0 comments on commit 8555c64

Please sign in to comment.