Skip to content

Commit 154860f

Browse files
iangudgerrsc
authored andcommitted
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 <[email protected]> Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent ce6aa2e commit 154860f

9 files changed

+30
-32
lines changed

api/except.txt

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ pkg syscall (darwin-386), const ImplementsGetwd = false
1919
pkg syscall (darwin-386-cgo), const ImplementsGetwd = false
2020
pkg syscall (darwin-amd64), const ImplementsGetwd = false
2121
pkg syscall (darwin-amd64-cgo), const ImplementsGetwd = false
22+
pkg syscall (linux-386), type Cmsghdr struct, X__cmsg_data [0]uint8
23+
pkg syscall (linux-386-cgo), type Cmsghdr struct, X__cmsg_data [0]uint8
24+
pkg syscall (linux-amd64), type Cmsghdr struct, X__cmsg_data [0]uint8
25+
pkg syscall (linux-amd64-cgo), type Cmsghdr struct, X__cmsg_data [0]uint8
26+
pkg syscall (linux-arm), type Cmsghdr struct, X__cmsg_data [0]uint8
27+
pkg syscall (linux-arm-cgo), type Cmsghdr struct, X__cmsg_data [0]uint8
2228
pkg syscall (openbsd-386), const BIOCGRTIMEOUT = 1074283118
2329
pkg syscall (openbsd-386), const BIOCSRTIMEOUT = 2148024941
2430
pkg syscall (openbsd-386), const RTF_FMASK = 63496

src/syscall/ztypes_linux_386.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,9 @@ type Msghdr struct {
238238
}
239239

240240
type Cmsghdr struct {
241-
Len uint32
242-
Level int32
243-
Type int32
244-
X__cmsg_data [0]uint8
241+
Len uint32
242+
Level int32
243+
Type int32
245244
}
246245

247246
type Inet4Pktinfo struct {

src/syscall/ztypes_linux_amd64.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ type Msghdr struct {
242242
}
243243

244244
type Cmsghdr struct {
245-
Len uint64
246-
Level int32
247-
Type int32
248-
X__cmsg_data [0]uint8
245+
Len uint64
246+
Level int32
247+
Type int32
249248
}
250249

251250
type Inet4Pktinfo struct {

src/syscall/ztypes_linux_arm.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ type Msghdr struct {
242242
}
243243

244244
type Cmsghdr struct {
245-
Len uint32
246-
Level int32
247-
Type int32
248-
X__cmsg_data [0]uint8
245+
Len uint32
246+
Level int32
247+
Type int32
249248
}
250249

251250
type Inet4Pktinfo struct {

src/syscall/ztypes_linux_arm64.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,9 @@ type Msghdr struct {
243243
}
244244

245245
type Cmsghdr struct {
246-
Len uint64
247-
Level int32
248-
Type int32
249-
X__cmsg_data [0]uint8
246+
Len uint64
247+
Level int32
248+
Type int32
250249
}
251250

252251
type Inet4Pktinfo struct {

src/syscall/ztypes_linux_mips64.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ type Msghdr struct {
244244
}
245245

246246
type Cmsghdr struct {
247-
Len uint64
248-
Level int32
249-
Type int32
250-
X__cmsg_data [0]uint8
247+
Len uint64
248+
Level int32
249+
Type int32
251250
}
252251

253252
type Inet4Pktinfo struct {

src/syscall/ztypes_linux_mips64le.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ type Msghdr struct {
244244
}
245245

246246
type Cmsghdr struct {
247-
Len uint64
248-
Level int32
249-
Type int32
250-
X__cmsg_data [0]uint8
247+
Len uint64
248+
Level int32
249+
Type int32
251250
}
252251

253252
type Inet4Pktinfo struct {

src/syscall/ztypes_linux_ppc64.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ type Msghdr struct {
244244
}
245245

246246
type Cmsghdr struct {
247-
Len uint64
248-
Level int32
249-
Type int32
250-
X__cmsg_data [0]uint8
247+
Len uint64
248+
Level int32
249+
Type int32
251250
}
252251

253252
type Inet4Pktinfo struct {

src/syscall/ztypes_linux_ppc64le.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ type Msghdr struct {
244244
}
245245

246246
type Cmsghdr struct {
247-
Len uint64
248-
Level int32
249-
Type int32
250-
X__cmsg_data [0]uint8
247+
Len uint64
248+
Level int32
249+
Type int32
251250
}
252251

253252
type Inet4Pktinfo struct {

0 commit comments

Comments
 (0)