Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plumbing: transport/ssh, Fix nil pointer dereference caused when an unreachable proxy server is set. Fixes #900 #901

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions plumbing/transport/ssh/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func dial(network, addr string, proxyOpts transport.ProxyOptions, config *ssh.Cl
defer cancel()

var conn net.Conn
var err error
var dialErr error

if proxyOpts.URL != "" {
proxyUrl, err := proxyOpts.FullURL()
Expand All @@ -186,12 +186,12 @@ func dial(network, addr string, proxyOpts transport.ProxyOptions, config *ssh.Cl
return nil, fmt.Errorf("expected ssh proxy dialer to be of type %s; got %s",
reflect.TypeOf(ctxDialer), reflect.TypeOf(dialer))
}
conn, err = ctxDialer.DialContext(ctx, "tcp", addr)
conn, dialErr = ctxDialer.DialContext(ctx, "tcp", addr)
} else {
conn, err = proxy.Dial(ctx, network, addr)
conn, dialErr = proxy.Dial(ctx, network, addr)
}
if err != nil {
return nil, err
if dialErr != nil {
return nil, dialErr
}

c, chans, reqs, err := ssh.NewClientConn(conn, addr, config)
Expand Down
22 changes: 22 additions & 0 deletions plumbing/transport/ssh/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ func (s *SuiteCommon) TestIssue70(c *C) {
c.Assert(err, IsNil)
}

/*
Given, an endpoint to a git server with a socks5 proxy URL,
When, the socks5 proxy server is not reachable,
Then, there should not be any panic and an error with appropriate message should be returned.
Related issue : https://github.com/go-git/go-git/pull/900
*/
func (s *SuiteCommon) TestInvalidSocks5Proxy(c *C) {
ep, err := transport.NewEndpoint("git@github.com:foo/bar.git")
c.Assert(err, IsNil)
ep.Proxy.URL = "socks5://127.0.0.1:1080"

auth, err := NewPublicKeys("foo", testdata.PEMBytes["rsa"], "")
c.Assert(err, IsNil)
c.Assert(auth, NotNil)

ps, err := DefaultClient.NewUploadPackSession(ep, auth)
//Since the proxy server is not running, we expect an error.
c.Assert(ps, IsNil)
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "socks connect .* dial tcp 127.0.0.1:1080: .*")
}

type mockSSHConfig struct {
Values map[string]map[string]string
}
Expand Down