Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
os/user: zero-initialize C structs returned to Go
In the wrappers for getgrnam_r and similar, the structs to be returned are allocated on the C stack and may be uninitialized. If the call to the wrapped C function returns an error (such as ERANGE), it may leave the struct uninitialized, expecting that the caller will not read it. However, when that struct is returned to Go, it may be read by the Go garbage collector. If the uninitialized struct fields happen to contain wild pointers, the Go garbage collector will throw an error. (Prior to CL 449335, the Go runtime would not scan the struct fields because they did not reside in Go memory.) Fix this by always zeroing the struct before the C call. Fixes #57170. Change-Id: I241ae8e4added6f9a406dac37a7f6452341aa0cf Reviewed-on: https://go-review.googlesource.com/c/go/+/456121 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
- Loading branch information