hit9 / tcptee

tcptee is a simple tcp traffic duplicator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

io.Writer implementation needs a nil check

pradhanbv opened this issue · comments

To reproduce bug, just remove one of the echo server run command from example.sh, but keep the port in backend list.
tcptee will crash if it is told to write to a port nobody is listening on.

I have fixed by adding nil check, this will handle backends which are not always available.

// Write implements the io.Writer.
func (b Backends) Write(p []byte) (n int, err error) {
for _, conn := range b {
if conn != nil {
n, err = conn.Write(p)
if err != nil {
return n, err
}
}
}
return
}