Skip to content

Commit 8014360

Browse files
zx2c4gopherbot
authored andcommitted
internal/syscall/unix: allow calling getrandom(..., 0, ...)
Calling getrandom() with a zero length is actually valid and useful: - Calling getrandom(..., 0, 0) will block until the RNG is initialized. - Calling getrandom(..., 0, GRND_NONBLOCK) will query whether the RNG is initialized. So instead of short circuiting execution for these circumstances, pass this through to the syscall. Change-Id: I15178f087908a2d8be6c020a1ef800cc0a074742 Reviewed-on: https://go-review.googlesource.com/c/go/+/615315 Run-TryBot: Jason Donenfeld <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Auto-Submit: Jason Donenfeld <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 3d6173a commit 8014360

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/internal/syscall/unix/getrandom.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ type GetRandomFlag uintptr
1919

2020
// GetRandom calls the getrandom system call.
2121
func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
22-
if len(p) == 0 {
23-
return 0, nil
24-
}
2522
if getrandomUnsupported.Load() {
2623
return 0, syscall.ENOSYS
2724
}
2825
r1, _, errno := syscall.Syscall(getrandomTrap,
29-
uintptr(unsafe.Pointer(&p[0])),
26+
uintptr(unsafe.Pointer(unsafe.SliceData(p))),
3027
uintptr(len(p)),
3128
uintptr(flags))
3229
if errno != 0 {

0 commit comments

Comments
 (0)