Browse Source

unix: fix nil pointer dereference in Select on linux/{arm64,mips64x}

The timeout parameter might be nil, don't dereference it
unconditionally.

CL 97819 did the same for the syscall package.

Updates golang/go#24189

Change-Id: I95a93468c7d8431abf2e9a3a9b8d0fbd1a223e0d
Reviewed-on: https://go-review.googlesource.com/97820
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 years ago
parent
commit
dd2ff4accc
2 changed files with 10 additions and 4 deletions
  1. 5 2
      unix/syscall_linux_arm64.go
  2. 5 2
      unix/syscall_linux_mips64x.go

+ 5 - 2
unix/syscall_linux_arm64.go

@@ -23,8 +23,11 @@ package unix
 //sys	Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
 
 func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
-	ts := Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
-	return Pselect(nfd, r, w, e, &ts, nil)
+	var ts *Timespec
+	if timeout != nil {
+		ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
+	}
+	return Pselect(nfd, r, w, e, ts, nil)
 }
 
 //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)

+ 5 - 2
unix/syscall_linux_mips64x.go

@@ -26,8 +26,11 @@ package unix
 //sys	Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
 
 func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
-	ts := Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
-	return Pselect(nfd, r, w, e, &ts, nil)
+	var ts *Timespec
+	if timeout != nil {
+		ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
+	}
+	return Pselect(nfd, r, w, e, ts, nil)
 }
 
 //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)