From 955e09dfbdb8a4cdae0a0b625001a567f6f15758 Mon Sep 17 00:00:00 2001 From: Ghanan Gowripalan Date: Fri, 6 Nov 2020 01:45:12 -0800 Subject: Do not send to the zero port Port 0 is not meant to identify any remote port so attempting to send a packet to it should return an error. PiperOrigin-RevId: 341009528 --- pkg/tcpip/transport/udp/endpoint.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pkg/tcpip/transport/udp') diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 56bdf6c34..9bcb918bb 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -487,6 +487,11 @@ func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, <-c nicID = e.BindNICID } + if to.Port == 0 { + // Port 0 is an invalid port to send to. + return 0, nil, tcpip.ErrInvalidEndpointState + } + dst, netProto, err := e.checkV4MappedLocked(*to) if err != nil { return 0, nil, err -- cgit v1.2.3