mirror of
https://github.com/coredns/coredns.git
synced 2026-06-15 21:50:11 -04:00
plugin/proxyproto: Prevent nil pointer dereference when dropping malformed PROXY packets (#8154)
Avoid a potential nil pointer dereference in PacketConn.ReadFrom() when malformed PROXY protocol headers cause readFrom() to return a nil address. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -70,6 +70,7 @@ func (c *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||
if err != nil {
|
||||
return n, addr, err
|
||||
}
|
||||
peer := addr
|
||||
n, addr, err = c.readFrom(p[:n], addr)
|
||||
if err != nil {
|
||||
if errors.Is(err, errHeaderOnly) {
|
||||
@@ -80,7 +81,7 @@ func (c *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||
}
|
||||
// drop invalid packet as returning error would cause the ReadFrom caller to exit
|
||||
// which could result in DoS if an attacker sends intentional invalid packets
|
||||
clog.Warningf("dropping invalid Proxy Protocol packet from %s: %v", addr.String(), err)
|
||||
clog.Warningf("dropping invalid Proxy Protocol packet from %s: %v", peer.String(), err)
|
||||
continue
|
||||
}
|
||||
return n, addr, nil
|
||||
|
||||
Reference in New Issue
Block a user