Bläddra i källkod

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>
Tobias Klauser 7 år sedan
förälder
incheckning
ad97f365e1
1 ändrade filer med 6 tillägg och 9 borttagningar
  1. 6 9
      unix/syscall_linux.go

+ 6 - 9
unix/syscall_linux.go

@@ -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(
-		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 {
 	if errno != 0 {
 		return 0, syscall.Errno(errno)
 		return 0, syscall.Errno(errno)
 	}
 	}