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

flag: integer overflow in intValue.Set and uintValue.Set #19230

Closed
perillo opened this issue Feb 21, 2017 · 5 comments
Closed

flag: integer overflow in intValue.Set and uintValue.Set #19230

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

Comments

@perillo
Copy link
Contributor

perillo commented Feb 21, 2017

Please answer these questions before submitting your issue. Thanks!

What did you do?

I set a command line flag of type flag.Int, but with a value greater then 2^31 - 1 on 32 bit systems the underlying value is set to 0, instead of reporting an error.

Here is a sample program:
https://play.golang.org/p/F7YNWJWt29

flag.Uint has the same problem.

What did you expect to see?

The program should exit with an error status and message.

What did you see instead?

The program prints

n is  0

System details

go version go1.8 linux/amd64
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/code/src/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build498162815=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version go1.8 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.8 X:framepointer
uname -sr: Linux 4.9.9-1-ARCH
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.24, by Roland McGrath et al.
gdb --version: GNU gdb (GDB) 7.12.1
@griesemer
Copy link
Contributor

As an aside, your example program has a bug: You need to add the "-number" string to the os.Args list as in: https://play.golang.org/p/k5yxZB7XmV .

Yet, still, the issue is present.

@griesemer
Copy link
Contributor

The code works correctly if you use flag.Int64 instead: https://play.golang.org/p/odbmwqKO3_ . Also, I believe you can define the how errors are handled explicitly: https://golang.org/pkg/flag/#ErrorHandling. So this may actually be working as intended.

@ianlancetaylor
Copy link
Contributor

@griesemer I don't think it is working as intended. The Set method has an error return, and it returns an error when the string can not be parsed or when the value is out of range of an int64. I think it should also be used when the value is out of range of an intValue.

@perillo
Copy link
Contributor Author

perillo commented Feb 21, 2017 via email

@bradfitz bradfitz added this to the Go1.9 milestone Mar 21, 2017
@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 21, 2017
@bradfitz bradfitz self-assigned this Mar 21, 2017
@gopherbot
Copy link

CL https://golang.org/cl/38419 mentions this issue.

@golang golang locked and limited conversation to collaborators Mar 21, 2018
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

5 participants