Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 501e9ad

Browse filesBrowse files
committed
plumbing: transport/ssh, Fix nil pointer dereference caused when an unreachable proxy server is set. Fixes #900
Signed-off-by: Anand Francis Joseph <anjoseph@redhat.com>
1 parent 6252084 commit 501e9ad
Copy full SHA for 501e9ad

File tree

Expand file treeCollapse file tree

2 files changed

+27
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-5
lines changed

‎plumbing/transport/ssh/common.go

Copy file name to clipboardExpand all lines: plumbing/transport/ssh/common.go
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func dial(network, addr string, proxyOpts transport.ProxyOptions, config *ssh.Cl
168168
defer cancel()
169169

170170
var conn net.Conn
171-
var err error
171+
var dialErr error
172172

173173
if proxyOpts.URL != "" {
174174
proxyUrl, err := proxyOpts.FullURL()
@@ -186,12 +186,12 @@ func dial(network, addr string, proxyOpts transport.ProxyOptions, config *ssh.Cl
186186
return nil, fmt.Errorf("expected ssh proxy dialer to be of type %s; got %s",
187187
reflect.TypeOf(ctxDialer), reflect.TypeOf(dialer))
188188
}
189-
conn, err = ctxDialer.DialContext(ctx, "tcp", addr)
189+
conn, dialErr = ctxDialer.DialContext(ctx, "tcp", addr)
190190
} else {
191-
conn, err = proxy.Dial(ctx, network, addr)
191+
conn, dialErr = proxy.Dial(ctx, network, addr)
192192
}
193-
if err != nil {
194-
return nil, err
193+
if dialErr != nil {
194+
return nil, dialErr
195195
}
196196

197197
c, chans, reqs, err := ssh.NewClientConn(conn, addr, config)

‎plumbing/transport/ssh/common_test.go

Copy file name to clipboardExpand all lines: plumbing/transport/ssh/common_test.go
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,28 @@ func (s *SuiteCommon) TestIssue70(c *C) {
172172
c.Assert(err, IsNil)
173173
}
174174

175+
/*
176+
Given, an endpoint to a git server with a socks5 proxy URL,
177+
When, the socks5 proxy server is not reachable,
178+
Then, there should not be any panic and an error with appropriate message should be returned.
179+
Related issue : https://github.com/go-git/go-git/pull/900
180+
*/
181+
func (s *SuiteCommon) TestInvalidSocks5Proxy(c *C) {
182+
ep, err := transport.NewEndpoint("git@github.com:foo/bar.git")
183+
c.Assert(err, IsNil)
184+
ep.Proxy.URL = "socks5://127.0.0.1:1080"
185+
186+
auth, err := NewPublicKeys("foo", testdata.PEMBytes["rsa"], "")
187+
c.Assert(err, IsNil)
188+
c.Assert(auth, NotNil)
189+
190+
ps, err := DefaultClient.NewUploadPackSession(ep, auth)
191+
//Since the proxy server is not running, we expect an error.
192+
c.Assert(ps, IsNil)
193+
c.Assert(err, NotNil)
194+
c.Assert(err, ErrorMatches, "socks connect .* dial tcp 127.0.0.1:1080: .*")
195+
}
196+
175197
type mockSSHConfig struct {
176198
Values map[string]map[string]string
177199
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.