Commit ad97f365 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: avoid index out of range in Vmsplice with empty iovs

Passing an empty iovs []Iovec slice to Vmsplice leads to an index out of
range panic. Fix this by passing an nil unsafe.Pointer to the underlying
syscall in case of an empty slice.

Change-Id: If1844c1b2eb0833de598aed7e79b9fcf061f7975
Reviewed-on: https://go-review.googlesource.com/c/153317
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 70b957f3
......@@ -1503,15 +1503,12 @@ func Munmap(b []byte) (err error) {
// Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd,
// using the specified flags.
func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
n, _, errno := Syscall6(
SYS_VMSPLICE,
uintptr(fd),
uintptr(unsafe.Pointer(&iovs[0])),
uintptr(len(iovs)),
uintptr(flags),
0,
0,
)
var p unsafe.Pointer
if len(iovs) > 0 {
p = unsafe.Pointer(&iovs[0])
}
n, _, errno := Syscall6(SYS_VMSPLICE, uintptr(fd), uintptr(p), uintptr(len(iovs)), uintptr(flags), 0, 0)
if errno != 0 {
return 0, syscall.Errno(errno)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment