os/user: fix signedness of UIDs before stringifying #22739

Closed
chipaca opened this Issue Nov 15, 2017 · 5 comments

Comments

Projects
None yet
3 participants
Contributor

chipaca commented Nov 15, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

at least 1.6 and 1.9 (haven't checked elsewhere)

Does this issue reproduce with the latest release?

that's 1.9, right?

What operating system and processor architecture are you using (go env)?

issue is with 32 bit Linux, only (so GOARCH of 386 and arm, and ppc)

What did you do?

given

package main

import (
	"fmt"
	"os/user"
	"syscall"
)

func main() {
	fmt.Printf("%x\n", syscall.Getuid())
	u, e := user.Current()
	fmt.Printf("%v %#v\n", e, u)
}

and

sudo useradd -u $(((1<<32)-2)) test123

and

CGO_ENABLED=1 GOARCH=386 go build userhi.go

What did you expect to see?

fffffffe
<nil> &user.User{Uid:"4294967294", Gid:"1001", Username:"test123", Name:"", HomeDir:"/home/test123"}

What did you see instead?

-1
user: unknown userid -1 (*user.User)(nil)
Owner

bradfitz commented Nov 15, 2017

We can fix os/user's User.Uid, but the Go 1 compatibility promise prevents us from changing the syscall.Getuid signature. You'll have to convert there. But it's the syscall package anyway, so people are expected to roll up their sleeves a bit.

@bradfitz bradfitz changed the title from `getuid` and co return signed integers; hilarity ensues to os/user: fix signedness of UIDs before stringifying Nov 15, 2017

@bradfitz bradfitz added the NeedsFix label Nov 15, 2017

@bradfitz bradfitz added this to the Go1.10 milestone Nov 15, 2017

Contributor

chipaca commented Nov 15, 2017

note the same applies to gid

Contributor

chipaca commented Nov 15, 2017

also, in case you're wondering, uids and gids of 0xffffffff aren't allowed because -1 is used as a flag to mean 'no change' for chown(2)

Change https://golang.org/cl/77930 mentions this issue: os/user: handle large 32-bit uid/gid values when stringifying User.Uid/Gid

@bradfitz bradfitz self-assigned this Nov 15, 2017

@gopherbot gopherbot closed this in 7edb721 Nov 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment