Skip to content

Commit a21b1c1

Browse files
committed
Added lock to strictly limit access to config.routes
1 parent 08e1ca7 commit a21b1c1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tcpproxy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ func (p *Proxy) AddRoute(ipPort string, dest Target) (routeID int) {
172172
// Both AddRoute and RemoveRoute is go-routine safe.
173173
func (p *Proxy) RemoveRoute(ipPort string, routeID int) {
174174
cfg := p.configFor(ipPort)
175+
cfg.Lock()
176+
defer cfg.Unlock()
175177
cfg.routes[routeID] = nil
176178
}
177179

@@ -255,6 +257,8 @@ func (p *Proxy) serveListener(ret chan<- error, ln net.Listener, cfg *config) {
255257
// It returns whether it matched purely for testing.
256258
func (p *Proxy) serveConn(c net.Conn, cfg *config) bool {
257259
br := bufio.NewReader(c)
260+
cfg.Lock()
261+
defer cfg.Unlock()
258262
for _, route := range cfg.routes {
259263
if route == nil {
260264
continue

0 commit comments

Comments
 (0)