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 {

View File

@@ -2,7 +2,6 @@ package proxyproto
import (
"bytes"
"io"
"net"
"testing"
"time"
@@ -259,7 +258,7 @@ func TestParse_BadHeader(t *testing.T) {
recv := make([]byte, 4)
_, err = conn.Read(recv)
if err != io.EOF {
if err == nil {
t.Fatalf("err: %v", err)
}
}()