Skip to content

Commit

Permalink
Fix Close connection for invalid header
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
keymon committed Jul 13, 2016
1 parent 49fdb5c commit efc48d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 2 additions & 0 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package proxyproto

import (
"bytes"
"io"
"net"
"testing"
"time"
Expand Down Expand Up @@ -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)
}
}()
Expand Down

0 comments on commit efc48d4

Please sign in to comment.