mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 08:37:31 -04:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
70b957f3b6
commit
ad97f365e1
@@ -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,
|
// Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd,
|
||||||
// using the specified flags.
|
// using the specified flags.
|
||||||
func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
|
func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
|
||||||
n, _, errno := Syscall6(
|
var p unsafe.Pointer
|
||||||
SYS_VMSPLICE,
|
if len(iovs) > 0 {
|
||||||
uintptr(fd),
|
p = unsafe.Pointer(&iovs[0])
|
||||||
uintptr(unsafe.Pointer(&iovs[0])),
|
}
|
||||||
uintptr(len(iovs)),
|
|
||||||
uintptr(flags),
|
n, _, errno := Syscall6(SYS_VMSPLICE, uintptr(fd), uintptr(p), uintptr(len(iovs)), uintptr(flags), 0, 0)
|
||||||
0,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
if errno != 0 {
|
if errno != 0 {
|
||||||
return 0, syscall.Errno(errno)
|
return 0, syscall.Errno(errno)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user