Skip to content

Commit 0410aab

Browse files
authored
Merge pull request microsoft#113 from Microsoft/close_nil_connset
Fix nil deref when closing ConnectionSet on error
2 parents 6587989 + 590f341 commit 0410aab

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

service/gcs/bridge/connection.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import (
44
"encoding/binary"
55
"io"
66

7-
"github.com/sirupsen/logrus"
8-
"github.com/pkg/errors"
9-
107
"github.com/Microsoft/opengcs/service/gcs/prot"
118
"github.com/Microsoft/opengcs/service/gcs/stdio"
129
"github.com/Microsoft/opengcs/service/gcs/transport"
10+
"github.com/pkg/errors"
11+
"github.com/sirupsen/logrus"
1312
)
1413

1514
const (
@@ -68,30 +67,30 @@ func sendResponseBytes(conn transport.Connection, messageType prot.MessageIdenti
6867
// connectStdio returns new transport.Connection instances, one for each
6968
// stdio pipe to be used. If CreateStd*Pipe for a given pipe is false, the
7069
// given Connection is set to nil.
71-
func connectStdio(tport transport.Transport, params prot.ProcessParameters, settings prot.ExecuteProcessVsockStdioRelaySettings) (s *stdio.ConnectionSet, err error) {
72-
s = &stdio.ConnectionSet{}
70+
func connectStdio(tport transport.Transport, params prot.ProcessParameters, settings prot.ExecuteProcessVsockStdioRelaySettings) (_ *stdio.ConnectionSet, err error) {
71+
connSet := &stdio.ConnectionSet{}
7372
defer func() {
7473
if err != nil {
75-
s.Close()
74+
connSet.Close()
7675
}
7776
}()
7877
if params.CreateStdInPipe {
79-
s.In, err = tport.Dial(settings.StdIn)
78+
connSet.In, err = tport.Dial(settings.StdIn)
8079
if err != nil {
8180
return nil, errors.Wrap(err, "failed creating stdin Connection")
8281
}
8382
}
8483
if params.CreateStdOutPipe {
85-
s.Out, err = tport.Dial(settings.StdOut)
84+
connSet.Out, err = tport.Dial(settings.StdOut)
8685
if err != nil {
8786
return nil, errors.Wrap(err, "failed creating stdout Connection")
8887
}
8988
}
9089
if params.CreateStdErrPipe {
91-
s.Err, err = tport.Dial(settings.StdErr)
90+
connSet.Err, err = tport.Dial(settings.StdErr)
9291
if err != nil {
9392
return nil, errors.Wrap(err, "failed creating stderr Connection")
9493
}
9594
}
96-
return s, nil
95+
return connSet, nil
9796
}

0 commit comments

Comments
 (0)