diff options
author | Wim <wim@42.be> | 2021-11-06 07:23:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-06 14:23:32 +0800 |
commit | bd613c704c0d74352d427ab32369310a04f5b721 (patch) | |
tree | 56a2184ba9d11a9170fa7b37b601992e90d6b6be | |
parent | 5e0cf4b82e10e72cd9754326e3183409afdb736c (diff) | |
download | gitea-bd613c704c0d74352d427ab32369310a04f5b721.tar.gz gitea-bd613c704c0d74352d427ab32369310a04f5b721.zip |
Fix ipv6 parsing for builtin ssh server (#17561)
-rw-r--r-- | integrations/git_helper_for_declarative_test.go | 3 | ||||
-rw-r--r-- | modules/ssh/ssh.go | 3 | ||||
-rw-r--r-- | routers/init.go | 6 |
3 files changed, 9 insertions, 3 deletions
diff --git a/integrations/git_helper_for_declarative_test.go b/integrations/git_helper_for_declarative_test.go index 9da5c05f94..71473ce464 100644 --- a/integrations/git_helper_for_declarative_test.go +++ b/integrations/git_helper_for_declarative_test.go @@ -13,6 +13,7 @@ import ( "os" "path" "path/filepath" + "strconv" "strings" "testing" "time" @@ -55,7 +56,7 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL { u2 := *u u2.Scheme = "ssh" u2.User = url.User("git") - u2.Host = fmt.Sprintf("%s:%d", setting.SSH.ListenHost, setting.SSH.ListenPort) + u2.Host = net.JoinHostPort(setting.SSH.ListenHost, strconv.Itoa(setting.SSH.ListenPort)) u2.Path = gitPath return &u2 } diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 909ed32c5e..5f19dd4a5c 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -17,6 +17,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "sync" "syscall" @@ -264,7 +265,7 @@ func sshConnectionFailed(conn net.Conn, err error) { // Listen starts a SSH server listens on given port. func Listen(host string, port int, ciphers []string, keyExchanges []string, macs []string) { srv := ssh.Server{ - Addr: fmt.Sprintf("%s:%d", host, port), + Addr: net.JoinHostPort(host, strconv.Itoa(port)), PublicKeyHandler: publicKeyHandler, Handler: sessionHandler, ServerConfigCallback: func(ctx ssh.Context) *gossh.ServerConfig { diff --git a/routers/init.go b/routers/init.go index a4f5f606ba..1e2b7a02f6 100644 --- a/routers/init.go +++ b/routers/init.go @@ -6,8 +6,10 @@ package routers import ( "context" + "net" "reflect" "runtime" + "strconv" "strings" "code.gitea.io/gitea/models" @@ -155,7 +157,9 @@ func GlobalInit(ctx context.Context) { if setting.SSH.StartBuiltinServer { ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs) - log.Info("SSH server started on %s:%d. Cipher list (%v), key exchange algorithms (%v), MACs (%v)", setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs) + log.Info("SSH server started on %s. Cipher list (%v), key exchange algorithms (%v), MACs (%v)", + net.JoinHostPort(setting.SSH.ListenHost, strconv.Itoa(setting.SSH.ListenPort)), + setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs) } else { ssh.Unused() } |