From e4099bfacb8c86adc69243822b224201edc89276 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Tue, 26 Sep 2023 16:55:16 +0300 Subject: [PATCH] unix: fix trimmed socket opt string in GetsockoptString Fixes golang/go#63217 Change-Id: Ia1b0ae88b7e7a7c611067a0b30e454b66f45ce51 Reviewed-on: https://go-review.googlesource.com/c/sys/+/530897 Reviewed-by: Mauri de Souza Meneguzzo Reviewed-by: Cherry Mui Auto-Submit: Tobias Klauser LUCI-TryBot-Result: Go LUCI Reviewed-by: Heschi Kreinick Reviewed-by: Tobias Klauser --- unix/syscall_bsd.go | 2 +- unix/syscall_linux.go | 2 +- unix/syscall_solaris.go | 2 +- unix/syscall_zos_s390x.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/unix/syscall_bsd.go b/unix/syscall_bsd.go index 6f328e3a5..a00c3e545 100644 --- a/unix/syscall_bsd.go +++ b/unix/syscall_bsd.go @@ -316,7 +316,7 @@ func GetsockoptString(fd, level, opt int) (string, error) { if err != nil { return "", err } - return string(buf[:vallen-1]), nil + return ByteSliceToString(buf[:vallen]), nil } //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 9b636ca07..0f85e29e6 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -1310,7 +1310,7 @@ func GetsockoptString(fd, level, opt int) (string, error) { return "", err } } - return string(buf[:vallen-1]), nil + return ByteSliceToString(buf[:vallen]), nil } func GetsockoptTpacketStats(fd, level, opt int) (*TpacketStats, error) { diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go index 60c8142d4..21974af06 100644 --- a/unix/syscall_solaris.go +++ b/unix/syscall_solaris.go @@ -158,7 +158,7 @@ func GetsockoptString(fd, level, opt int) (string, error) { if err != nil { return "", err } - return string(buf[:vallen-1]), nil + return ByteSliceToString(buf[:vallen]), nil } const ImplementsGetwd = true diff --git a/unix/syscall_zos_s390x.go b/unix/syscall_zos_s390x.go index d99d05f1b..b473038c6 100644 --- a/unix/syscall_zos_s390x.go +++ b/unix/syscall_zos_s390x.go @@ -1104,7 +1104,7 @@ func GetsockoptString(fd, level, opt int) (string, error) { return "", err } - return string(buf[:vallen-1]), nil + return ByteSliceToString(buf[:vallen]), nil } func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) {