mirror of
https://github.com/golang/go
synced 2024-11-19 11:44:45 -07:00
os/user: handle large 32-bit uid/gid values when stringifying User.Uid/Gid
Fixes #22739 Change-Id: I374c29d237c498c9e5ac848b01f6d49d7c41b31f Reviewed-on: https://go-review.googlesource.com/77930 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
92c3582471
commit
7edb721fbc
@ -114,8 +114,8 @@ func lookupUnixUid(uid int) (*User, error) {
|
|||||||
|
|
||||||
func buildUser(pwd *C.struct_passwd) *User {
|
func buildUser(pwd *C.struct_passwd) *User {
|
||||||
u := &User{
|
u := &User{
|
||||||
Uid: strconv.Itoa(int(pwd.pw_uid)),
|
Uid: strconv.FormatUint(uint64(pwd.pw_uid), 10),
|
||||||
Gid: strconv.Itoa(int(pwd.pw_gid)),
|
Gid: strconv.FormatUint(uint64(pwd.pw_gid), 10),
|
||||||
Username: C.GoString(pwd.pw_name),
|
Username: C.GoString(pwd.pw_name),
|
||||||
Name: C.GoString(pwd.pw_gecos),
|
Name: C.GoString(pwd.pw_gecos),
|
||||||
HomeDir: C.GoString(pwd.pw_dir),
|
HomeDir: C.GoString(pwd.pw_dir),
|
||||||
@ -269,3 +269,11 @@ const maxBufferSize = 1 << 20
|
|||||||
func isSizeReasonable(sz int64) bool {
|
func isSizeReasonable(sz int64) bool {
|
||||||
return sz > 0 && sz <= maxBufferSize
|
return sz > 0 && sz <= maxBufferSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Because we can't use cgo in tests:
|
||||||
|
func structPasswdForNegativeTest() C.struct_passwd {
|
||||||
|
sp := C.struct_passwd{}
|
||||||
|
sp.pw_uid = 1<<32 - 2
|
||||||
|
sp.pw_gid = 1<<32 - 3
|
||||||
|
return sp
|
||||||
|
}
|
||||||
|
24
src/os/user/cgo_unix_test.go
Normal file
24
src/os/user/cgo_unix_test.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2017 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build darwin dragonfly freebsd !android,linux netbsd openbsd solaris
|
||||||
|
// +build cgo
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Issue 22739
|
||||||
|
func TestNegativeUid(t *testing.T) {
|
||||||
|
sp := structPasswdForNegativeTest()
|
||||||
|
u := buildUser(&sp)
|
||||||
|
if g, w := u.Uid, "4294967294"; g != w {
|
||||||
|
t.Errorf("Uid = %q; want %q", g, w)
|
||||||
|
}
|
||||||
|
if g, w := u.Gid, "4294967293"; g != w {
|
||||||
|
t.Errorf("Gid = %q; want %q", g, w)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user