Skip to content

Commit

Permalink
Protect against slice index error when checking for exec:/
Browse files Browse the repository at this point in the history
- Ensure that a short string produces a different error.
- Add test for "no such host"
  • Loading branch information
rwstauner committed Oct 4, 2019
1 parent 93f22ab commit 290d3a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func dialWithRetries(network string, address string, timeout time.Duration) (con
// Not for bad ports, etc.
case *net.AddrError, net.InvalidAddrError:
return
// Connection Refused (*os.SyscallError) also counts as Temporary,
// but that's precisely the error we want to retry.
// Some errors are not considered Temporary
// but are precisely the sort of errors we want to retry:
// - connection refused (*os.SyscallError)
// - no such host (*.netDNSError)
default:
}
}
Expand All @@ -57,7 +59,7 @@ func dialWithRetries(network string, address string, timeout time.Duration) (con
}

func (s *Service) handleConnection(src *net.TCPConn, dst string, done chan bool) {
if dst[0:6] == "exec:/" {
if len(dst) > 5 && dst[0:6] == "exec:/" {
var stdout, stderr bytes.Buffer
path := dst[5:len(dst)]
cmd := exec.Command(path)
Expand Down
7 changes: 7 additions & 0 deletions test/errors.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ load helpers
# Should be instant, rather than timing out.
ylog | grep -qF -- "dial tcp: address foobar: missing port in address"
}

@test "bad host" {
ynetd -timeout 0s -proxy ":$LISTEN_PORT .:1"
knock
sleep 1
ylog | grep -qF -- "dial tcp: lookup .: no such host"
}

0 comments on commit 290d3a6

Please sign in to comment.