From b9747e0e6b82c6de1ebe020841087e8fb1eabccc Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 7 Dec 2022 13:27:22 -0800 Subject: [PATCH] os/user: on AIX getpwuid_r seems to return -1 on overflow The getpwuid_r function is expected to return ERANGE on overflow. Accept -1 on AIX as we see that in practice. This problem was uncovered by, but not caused by, CL 455815, which introduced a test that forced a buffer overflow. Change-Id: I3ae94faf1257d2c73299b1478e49769bb807fc4d Reviewed-on: https://go-review.googlesource.com/c/go/+/456075 Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/os/user/cgo_lookup_unix.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/os/user/cgo_lookup_unix.go b/src/os/user/cgo_lookup_unix.go index b745ffd9cf..3735971eb4 100644 --- a/src/os/user/cgo_lookup_unix.go +++ b/src/os/user/cgo_lookup_unix.go @@ -8,6 +8,7 @@ package user import ( "fmt" + "runtime" "strconv" "strings" "syscall" @@ -170,6 +171,9 @@ func retryWithBuffer(startSize bufferKind, f func([]byte) syscall.Errno) error { errno := f(buf) if errno == 0 { return nil + } else if runtime.GOOS == "aix" && errno+1 == 0 { + // On AIX getpwuid_r appears to return -1, + // not ERANGE, on buffer overflow. } else if errno != syscall.ERANGE { return errno }