Skip to content

Commit c04e08e

Browse files
committed
Fix ipv6 parsing for builtin ssh server
1 parent 5e0cf4b commit c04e08e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

integrations/git_helper_for_declarative_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os"
1414
"path"
1515
"path/filepath"
16+
"strconv"
1617
"strings"
1718
"testing"
1819
"time"
@@ -55,7 +56,7 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
5556
u2 := *u
5657
u2.Scheme = "ssh"
5758
u2.User = url.User("git")
58-
u2.Host = fmt.Sprintf("%s:%d", setting.SSH.ListenHost, setting.SSH.ListenPort)
59+
u2.Host = net.JoinHostPort(setting.SSH.ListenHost, strconv.Itoa(setting.SSH.ListenPort))
5960
u2.Path = gitPath
6061
return &u2
6162
}

modules/ssh/ssh.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"os"
1818
"os/exec"
1919
"path/filepath"
20+
"strconv"
2021
"strings"
2122
"sync"
2223
"syscall"
@@ -264,7 +265,7 @@ func sshConnectionFailed(conn net.Conn, err error) {
264265
// Listen starts a SSH server listens on given port.
265266
func Listen(host string, port int, ciphers []string, keyExchanges []string, macs []string) {
266267
srv := ssh.Server{
267-
Addr: fmt.Sprintf("%s:%d", host, port),
268+
Addr: net.JoinHostPort(host, strconv.Itoa(port)),
268269
PublicKeyHandler: publicKeyHandler,
269270
Handler: sessionHandler,
270271
ServerConfigCallback: func(ctx ssh.Context) *gossh.ServerConfig {

routers/init.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ package routers
66

77
import (
88
"context"
9+
"net"
910
"reflect"
1011
"runtime"
12+
"strconv"
1113
"strings"
1214

1315
"code.gitea.io/gitea/models"
@@ -155,7 +157,9 @@ func GlobalInit(ctx context.Context) {
155157

156158
if setting.SSH.StartBuiltinServer {
157159
ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs)
158-
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)
160+
log.Info("SSH server started on %s. Cipher list (%v), key exchange algorithms (%v), MACs (%v)",
161+
net.JoinHostPort(setting.SSH.ListenHost, strconv.Itoa(setting.SSH.ListenPort)),
162+
setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs)
159163
} else {
160164
ssh.Unused()
161165
}

0 commit comments

Comments
 (0)