Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

chipaca opened this issue Nov 15, 2017 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@chipaca
Copy link
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)
@bradfitz
Copy link
Contributor

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 getuid and co return signed integers; hilarity ensues os/user: fix signedness of UIDs before stringifying Nov 15, 2017
@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 15, 2017
@bradfitz bradfitz added this to the Go1.10 milestone Nov 15, 2017
@chipaca
Copy link
Contributor Author

chipaca commented Nov 15, 2017

note the same applies to gid

@chipaca
Copy link
Contributor Author

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)

@gopherbot
Copy link
Contributor

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

@bradfitz
Copy link
Contributor

I handled gid in https://go-review.googlesource.com/#/c/go/+/77930 too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants