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:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user