From 1023b016d51ee0e6b7245482b9d8715170d785ee Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 1 Mar 2018 09:20:26 +0100 Subject: [PATCH] syscall: fix nil pointer dereference in Select on linux/{arm64,mips64x} The timeout parameter might be nil, don't dereference it unconditionally. Fixes #24189 Change-Id: I03e6a1ab74fe30322ce6bcfd3d6c42130b6d61be Reviewed-on: https://go-review.googlesource.com/97819 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/syscall_linux_arm64.go | 7 +++++-- src/syscall/syscall_linux_mips64x.go | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/syscall/syscall_linux_arm64.go b/src/syscall/syscall_linux_arm64.go index 27c351d7bd..10270cfd00 100644 --- a/src/syscall/syscall_linux_arm64.go +++ b/src/syscall/syscall_linux_arm64.go @@ -74,8 +74,11 @@ type sigset_t struct { //sys pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_t) (n int, err error) = SYS_PSELECT6 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) } //sysnb Gettimeofday(tv *Timeval) (err error) diff --git a/src/syscall/syscall_linux_mips64x.go b/src/syscall/syscall_linux_mips64x.go index d9eba62b06..e9bc01f8a0 100644 --- a/src/syscall/syscall_linux_mips64x.go +++ b/src/syscall/syscall_linux_mips64x.go @@ -65,8 +65,11 @@ type sigset_t struct { //sys pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_t) (n int, err error) = SYS_PSELECT6 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) } //sysnb Gettimeofday(tv *Timeval) (err error) -- 2.50.0