From 9c2ac6fbd5a12b3f30feb78f3d358dca31603a86 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 31 Jul 2020 16:20:31 +0200 Subject: [PATCH] rpc: remove silly use of ReadVarint in subscription ID generator (#21391) Found by @protolambda --- rpc/subscription.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rpc/subscription.go b/rpc/subscription.go index f9d60dcb98..233215d792 100644 --- a/rpc/subscription.go +++ b/rpc/subscription.go @@ -17,7 +17,6 @@ package rpc import ( - "bufio" "container/list" "context" crand "crypto/rand" @@ -51,10 +50,14 @@ func NewID() ID { // randomIDGenerator returns a function generates a random IDs. func randomIDGenerator() func() ID { - seed, err := binary.ReadVarint(bufio.NewReader(crand.Reader)) - if err != nil { + var buf = make([]byte, 8) + var seed int64 + if _, err := crand.Read(buf); err == nil { + seed = int64(binary.BigEndian.Uint64(buf)) + } else { seed = int64(time.Now().Nanosecond()) } + var ( mu sync.Mutex rng = rand.New(rand.NewSource(seed))