Skip to content

Commit 0ba0010

Browse files
authored
gzhttp: Fix crypto/rand.Read usage (#770)
rand.Reader.Read(p) is allowed to return < len(p) bytes and no error, and the Mac implementation sometimes does. I don't know if it will do that for len(p) == 4, but rand.Read is safer in any case.
1 parent cd2407a commit 0ba0010

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

gzhttp/compress.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ func (w *GzipResponseWriter) startGzip(remain []byte) error {
231231
} else {
232232
// Get from rand.Reader
233233
var tmp [4]byte
234-
_, err := rand.Reader.Read(tmp[:])
234+
_, err := rand.Read(tmp[:])
235235
if err != nil {
236-
return err
236+
return fmt.Errorf("gzhttp: %w", err)
237237
}
238238
jitRNG = binary.LittleEndian.Uint32(tmp[:])
239239
}

0 commit comments

Comments
 (0)