File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ func (s *Server) x11Handler(ctx ssh.Context, x11 ssh.X11) bool {
61
61
62
62
go func () {
63
63
defer s .trackListener (listener , false )
64
+ handledFirstConnection := false
64
65
65
66
for {
66
67
conn , err := listener .Accept ()
@@ -71,6 +72,13 @@ func (s *Server) x11Handler(ctx ssh.Context, x11 ssh.X11) bool {
71
72
s .logger .Warn (ctx , "failed to accept X11 connection" , slog .Error (err ))
72
73
return
73
74
}
75
+ if x11 .SingleConnection && handledFirstConnection {
76
+ s .logger .Warn (ctx , "X11 connection rejected because single connection is enabled" )
77
+ _ = conn .Close ()
78
+ continue
79
+ }
80
+ handledFirstConnection = true
81
+
74
82
unixConn , ok := conn .(* net.UnixConn )
75
83
if ! ok {
76
84
s .logger .Warn (ctx , fmt .Sprintf ("failed to cast connection to UnixConn. got: %T" , conn ))
Original file line number Diff line number Diff line change @@ -68,9 +68,12 @@ func TestServer_X11(t *testing.T) {
68
68
require .NoError (t , err )
69
69
70
70
x11Chans := c .HandleChannelOpen ("x11" )
71
+ payload := "hello world"
71
72
require .Eventually (t , func () bool {
72
73
conn , err := net .Dial ("unix" , filepath .Join (dir , "X0" ))
73
74
if err == nil {
75
+ _ , err = conn .Write ([]byte (payload ))
76
+ assert .NoError (t , err )
74
77
_ = conn .Close ()
75
78
}
76
79
return err == nil
@@ -80,9 +83,12 @@ func TestServer_X11(t *testing.T) {
80
83
ch , reqs , err := x11 .Accept ()
81
84
require .NoError (t , err )
82
85
go gossh .DiscardRequests (reqs )
83
- err = ch .Close ()
86
+ got := make ([]byte , len (payload ))
87
+ _ , err = ch .Read (got )
84
88
require .NoError (t , err )
85
- s .Close ()
89
+ assert .Equal (t , payload , string (got ))
90
+ _ = ch .Close ()
91
+ _ = s .Close ()
86
92
<- done
87
93
88
94
// Ensure the Xauthority file was written!
You can’t perform that action at this time.
0 commit comments