From 154860ff17dacbf309ed247277d245ec887af6d4 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Fri, 28 Oct 2016 20:09:02 -0700 Subject: [PATCH] syscall: remove X__cmsg_data from Cmsghdr This field is a zero length array and has little use. Since Go 1.5, trailing zero-length arrays take up space. Both syscall.UnixRights() and syscall.ParseSocketControlMessage() depend on being able to do an unsafe cast of socket control message data to Cmsghdr this is only safe if the socket control message data is greater than or equal to the size of Cmsghdr. Since control message data that is equal in size to Cmsghdr without X__cmsg_data is a valid socket control message, we must remove X__cmsg_data or not perform the unsafe cast. Removing X__cmsg_data will prevent Go code that uses X__cmsg_data from compiling, but removing the unsafe cast will cause Go code that uses X__cmsg_data to fail or exhibit undefined behavior at runtime. It was therefore decided that removing X__cmsg_data was the better option. Fixes #17649 Change-Id: I39f323f978eca09d62da5785c5c5c9c7cbdf8c31 Reviewed-on: https://go-review.googlesource.com/32319 Reviewed-by: Ian Lance Taylor Reviewed-by: Russ Cox Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- api/except.txt | 6 ++++++ src/syscall/ztypes_linux_386.go | 7 +++---- src/syscall/ztypes_linux_amd64.go | 7 +++---- src/syscall/ztypes_linux_arm.go | 7 +++---- src/syscall/ztypes_linux_arm64.go | 7 +++---- src/syscall/ztypes_linux_mips64.go | 7 +++---- src/syscall/ztypes_linux_mips64le.go | 7 +++---- src/syscall/ztypes_linux_ppc64.go | 7 +++---- src/syscall/ztypes_linux_ppc64le.go | 7 +++---- 9 files changed, 30 insertions(+), 32 deletions(-) diff --git a/api/except.txt b/api/except.txt index 93302ec819..cd5d8e0df5 100644 --- a/api/except.txt +++ b/api/except.txt @@ -19,6 +19,12 @@ pkg syscall (darwin-386), const ImplementsGetwd = false pkg syscall (darwin-386-cgo), const ImplementsGetwd = false pkg syscall (darwin-amd64), const ImplementsGetwd = false pkg syscall (darwin-amd64-cgo), const ImplementsGetwd = false +pkg syscall (linux-386), type Cmsghdr struct, X__cmsg_data [0]uint8 +pkg syscall (linux-386-cgo), type Cmsghdr struct, X__cmsg_data [0]uint8 +pkg syscall (linux-amd64), type Cmsghdr struct, X__cmsg_data [0]uint8 +pkg syscall (linux-amd64-cgo), type Cmsghdr struct, X__cmsg_data [0]uint8 +pkg syscall (linux-arm), type Cmsghdr struct, X__cmsg_data [0]uint8 +pkg syscall (linux-arm-cgo), type Cmsghdr struct, X__cmsg_data [0]uint8 pkg syscall (openbsd-386), const BIOCGRTIMEOUT = 1074283118 pkg syscall (openbsd-386), const BIOCSRTIMEOUT = 2148024941 pkg syscall (openbsd-386), const RTF_FMASK = 63496 diff --git a/src/syscall/ztypes_linux_386.go b/src/syscall/ztypes_linux_386.go index dd198cb394..a73c91770f 100644 --- a/src/syscall/ztypes_linux_386.go +++ b/src/syscall/ztypes_linux_386.go @@ -238,10 +238,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint32 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint32 + Level int32 + Type int32 } type Inet4Pktinfo struct { diff --git a/src/syscall/ztypes_linux_amd64.go b/src/syscall/ztypes_linux_amd64.go index a39489e4e5..4cbd5d899d 100644 --- a/src/syscall/ztypes_linux_amd64.go +++ b/src/syscall/ztypes_linux_amd64.go @@ -242,10 +242,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint64 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint64 + Level int32 + Type int32 } type Inet4Pktinfo struct { diff --git a/src/syscall/ztypes_linux_arm.go b/src/syscall/ztypes_linux_arm.go index f446e41be0..16aa014ada 100644 --- a/src/syscall/ztypes_linux_arm.go +++ b/src/syscall/ztypes_linux_arm.go @@ -242,10 +242,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint32 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint32 + Level int32 + Type int32 } type Inet4Pktinfo struct { diff --git a/src/syscall/ztypes_linux_arm64.go b/src/syscall/ztypes_linux_arm64.go index dcb1178dc4..e5d669cdba 100644 --- a/src/syscall/ztypes_linux_arm64.go +++ b/src/syscall/ztypes_linux_arm64.go @@ -243,10 +243,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint64 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint64 + Level int32 + Type int32 } type Inet4Pktinfo struct { diff --git a/src/syscall/ztypes_linux_mips64.go b/src/syscall/ztypes_linux_mips64.go index 909308617e..925afb9d1c 100644 --- a/src/syscall/ztypes_linux_mips64.go +++ b/src/syscall/ztypes_linux_mips64.go @@ -244,10 +244,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint64 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint64 + Level int32 + Type int32 } type Inet4Pktinfo struct { diff --git a/src/syscall/ztypes_linux_mips64le.go b/src/syscall/ztypes_linux_mips64le.go index 909308617e..925afb9d1c 100644 --- a/src/syscall/ztypes_linux_mips64le.go +++ b/src/syscall/ztypes_linux_mips64le.go @@ -244,10 +244,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint64 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint64 + Level int32 + Type int32 } type Inet4Pktinfo struct { diff --git a/src/syscall/ztypes_linux_ppc64.go b/src/syscall/ztypes_linux_ppc64.go index 915ca95190..de817f50af 100644 --- a/src/syscall/ztypes_linux_ppc64.go +++ b/src/syscall/ztypes_linux_ppc64.go @@ -244,10 +244,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint64 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint64 + Level int32 + Type int32 } type Inet4Pktinfo struct { diff --git a/src/syscall/ztypes_linux_ppc64le.go b/src/syscall/ztypes_linux_ppc64le.go index a1180553ec..e75d8e3925 100644 --- a/src/syscall/ztypes_linux_ppc64le.go +++ b/src/syscall/ztypes_linux_ppc64le.go @@ -244,10 +244,9 @@ type Msghdr struct { } type Cmsghdr struct { - Len uint64 - Level int32 - Type int32 - X__cmsg_data [0]uint8 + Len uint64 + Level int32 + Type int32 } type Inet4Pktinfo struct { -- 2.48.1