mirror of
https://github.com/golang/go
synced 2024-11-22 00:44:39 -07:00
crypto/rand: zero length reads shouldn't crash on Windows.
R=golang-dev, dave CC=golang-dev https://golang.org/cl/6496099
This commit is contained in:
parent
ae0862c1ec
commit
b752ab2e90
@ -30,3 +30,14 @@ func TestRead(t *testing.T) {
|
||||
t.Fatalf("Compressed %d -> %d", len(b), z.Len())
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadEmpty(t *testing.T) {
|
||||
n, err := Reader.Read(make([]byte, 0))
|
||||
if n != 0 || err != nil {
|
||||
t.Fatalf("Read(make([]byte, 0)) = %d, %v", n, err)
|
||||
}
|
||||
n, err = Reader.Read(nil)
|
||||
if n != 0 || err != nil {
|
||||
t.Fatalf("Read(make(nil) = %d, %v", n, err)
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,10 @@ func (r *rngReader) Read(b []byte) (n int, err error) {
|
||||
}
|
||||
}
|
||||
r.mu.Unlock()
|
||||
|
||||
if len(b) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
err = syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
|
||||
if err != nil {
|
||||
return 0, os.NewSyscallError("CryptGenRandom", err)
|
||||
|
Loading…
Reference in New Issue
Block a user