]> Cypherpunks repositories - gostls13.git/commitdiff
os/user: on AIX getpwuid_r seems to return -1 on overflow
authorIan Lance Taylor <iant@golang.org>
Wed, 7 Dec 2022 21:27:22 +0000 (13:27 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 8 Dec 2022 03:49:48 +0000 (03:49 +0000)
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 <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/os/user/cgo_lookup_unix.go

index b745ffd9cf44ea8675de0abe5d0912af822de280..3735971eb4b7b4b87a456ea1d6b0117c6f087889 100644 (file)
@@ -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
                }