Skip to content

Commit 269f66d

Browse files
committed
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.
1 parent 5281009 commit 269f66d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

protocol.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func (p *Conn) RemoteAddr() net.Addr {
110110
p.once.Do(func() {
111111
if err := p.checkPrefix(); err != nil && err != io.EOF {
112112
log.Printf("[ERR] Failed to read proxy prefix: %v", err)
113+
p.Close()
114+
p.bufReader = bufio.NewReader(p.conn)
113115
}
114116
})
115117
if p.srcAddr != nil {

protocol_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package proxyproto
22

33
import (
44
"bytes"
5-
"io"
65
"net"
76
"testing"
87
"time"
@@ -258,7 +257,7 @@ func TestParse_BadHeader(t *testing.T) {
258257

259258
recv := make([]byte, 4)
260259
_, err = conn.Read(recv)
261-
if err != io.EOF {
260+
if err == nil {
262261
t.Fatalf("err: %v", err)
263262
}
264263
}()

0 commit comments

Comments
 (0)