]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: check sched_getaffinity return value
authorMichael Marineau <mike@marineau.org>
Tue, 3 Jan 2017 08:15:05 +0000 (00:15 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 3 Jan 2017 22:35:42 +0000 (22:35 +0000)
Android on ChromeOS uses a restrictive seccomp filter that blocks
sched_getaffinity, leading this code to index a slice by -errno.

Change-Id: Iec09a4f79dfbc17884e24f39bcfdad305de75b37
Reviewed-on: https://go-review.googlesource.com/34794
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

src/runtime/os_linux.go

index 213b951a6b5239a6e12ac4cea3b0631b7254f634..a6efc0e3d1f11f10fe2770153bdfb8ee3baff8df 100644 (file)
@@ -91,6 +91,9 @@ func getproccount() int32 {
        const maxCPUs = 64 * 1024
        var buf [maxCPUs / (sys.PtrSize * 8)]uintptr
        r := sched_getaffinity(0, unsafe.Sizeof(buf), &buf[0])
+       if r < 0 {
+               return 1
+       }
        n := int32(0)
        for _, v := range buf[:r/sys.PtrSize] {
                for v != 0 {