Skip to content

Commit 37b3cba

Browse files
jwhitedzx2c4
authored andcommitted
conn: ensure control message size is respected in StdNetBind
This commit re-slices received control messages in StdNetBind to the value the OS reports on a successful read. Previously, the len of this slice would always be srcControlSize, which could result in control message values leaking through a sync.Pool round trip. This is unlikely with the IP_PKTINFO socket option set successfully, but should be guarded against. Signed-off-by: James Tucker <[email protected]> Signed-off-by: Jordan Whited <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent d887562 commit 37b3cba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

conn/bind_std.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (s *StdNetBind) makeReceiveIPv4(pc *ipv4.PacketConn, conn *net.UDPConn) Rec
229229
sizes[i] = msg.N
230230
addrPort := msg.Addr.(*net.UDPAddr).AddrPort()
231231
ep := asEndpoint(addrPort)
232-
getSrcFromControl(msg.OOB, ep)
232+
getSrcFromControl(msg.OOB[:msg.NN], ep)
233233
eps[i] = ep
234234
}
235235
return numMsgs, nil
@@ -262,7 +262,7 @@ func (s *StdNetBind) makeReceiveIPv6(pc *ipv6.PacketConn, conn *net.UDPConn) Rec
262262
sizes[i] = msg.N
263263
addrPort := msg.Addr.(*net.UDPAddr).AddrPort()
264264
ep := asEndpoint(addrPort)
265-
getSrcFromControl(msg.OOB, ep)
265+
getSrcFromControl(msg.OOB[:msg.NN], ep)
266266
eps[i] = ep
267267
}
268268
return numMsgs, nil

0 commit comments

Comments
 (0)