unix: allow empty string argument to SetsockoptString

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>
This commit is contained in:
Tobias Klauser
2019-04-05 15:42:28 +00:00
committed by Tobias Klauser
parent 81d4e9dc47
commit 4b34438f7a
2 changed files with 13 additions and 1 deletions
+8
View File
@@ -403,6 +403,14 @@ func TestSeekFailure(t *testing.T) {
}
}
func TestSetsockoptString(t *testing.T) {
// should not panic on empty string, see issue #31277
err := unix.SetsockoptString(-1, 0, 0, "")
if err == nil {
t.Fatalf("SetsockoptString: did not fail")
}
}
func TestDup(t *testing.T) {
file, err := ioutil.TempFile("", "TestDup")
if err != nil {