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

Comments

@abarisani
Copy link

@abarisani abarisani commented Apr 5, 2019

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 bradfitz commented Apr 5, 2019

@bradfitz bradfitz added the NeedsFix 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

@gopherbot gopherbot commented Apr 5, 2019

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

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 5, 2019

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>
@gopherbot gopherbot closed this in db0c524 Apr 5, 2019
@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.