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

syscall: SetsockoptString does not allow empty strings #31277

Closed
abarisani opened this issue Apr 5, 2019 · 3 comments
Closed

syscall: SetsockoptString does not allow empty strings #31277

abarisani opened this issue Apr 5, 2019 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@abarisani
Copy link

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

$ go version go1.12.1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

Linux

What did you do?

syscall.SetsockoptString(1, 2, 3, "")

What did you expect to see?

It would be expected for an empty string to still allow the call.

What did you see instead?

panic: runtime error: index out of range

goroutine 1 [running]:
syscall.SetsockoptString(...)
	/usr/lib/go/src/syscall/syscall_unix.go:309

This happens because of the following code at https://golang.org/src/syscall/syscall_unix.go?s=7074:7137#L298:

return setsockopt(fd, level, opt, unsafe.Pointer(&[]byte(s)[0]), uintptr(len(s)))

The use of the [0] index is not compatible with an empty string.

However sometimes SETSOCKOPT with empty string is required, it would be nice to be able to do so without having to resort to use syscall.Syscall6 (for arm as an example) or whatever architecture dependent equivalent.

Thanks!

@bradfitz
Copy link
Contributor

bradfitz commented Apr 5, 2019

/cc @tklauser @ianlancetaylor

@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 5, 2019
@bradfitz bradfitz added this to the Go1.13 milestone Apr 5, 2019
@bradfitz bradfitz changed the title syscall.SetsockoptString does not allow empty strings syscall: SetsockoptString does not allow empty strings Apr 5, 2019
@gopherbot
Copy link

Change https://golang.org/cl/170937 mentions this issue: syscall: allow empty string argument to SetsockoptString

@gopherbot
Copy link

Change https://golang.org/cl/170957 mentions this issue: unix: allow empty string argument to SetsockoptString

gopherbot pushed a commit to golang/sys that referenced this issue Apr 5, 2019
Don't panic with "index out of range" on empty string argument.

Follows CL 170937 which did the sane for package syscall.

Updates golang/go#31277

Change-Id: I4feb796d0d58d3637428ae69997cfa3ec28a6b01
Reviewed-on: https://go-review.googlesource.com/c/sys/+/170957
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@golang golang locked and limited conversation to collaborators Apr 4, 2020
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