Fix Close connection for invalid header

RemoteAddr() must close the connection and clear the buffer if we
receive a invalid PROXY protocol header.

Change the client test as it can get an EOF or a ECONNRESET.
This commit is contained in:
Hector Rivas Gandara
2016-07-13 15:20:54 +01:00
parent 49fdb5cfab
commit efc48d41bc
2 changed files with 3 additions and 2 deletions

View File

@@ -110,6 +110,8 @@ func (p *Conn) RemoteAddr() net.Addr {
p.once.Do(func() {
if err := p.checkPrefix(); err != nil && err != io.EOF {
log.Printf("[ERR] Failed to read proxy prefix: %v", err)
p.Close()
p.bufReader = bufio.NewReader(p.conn)
}
})
if p.srcAddr != nil {