wgengine: fix bugs from earlier fix

Fixes a regression from e970ed0995 that wasn't covered by tests
in this repo. (Our end-to-end tests in another repo caught this.)

Updates #1204
pull/1211/head
Brad Fitzpatrick 4 years ago
parent 4dab0c1702
commit 9f5b0d058f

@ -1035,6 +1035,8 @@ func (e *userspaceEngine) getStatusCallback() StatusCallback {
return e.statusCallback return e.statusCallback
} }
var singleNewline = []byte{'\n'}
func (e *userspaceEngine) getStatus() (*Status, error) { func (e *userspaceEngine) getStatus() (*Status, error) {
// Grab derpConns before acquiring wgLock to not violate lock ordering; // Grab derpConns before acquiring wgLock to not violate lock ordering;
// the DERPs method acquires magicsock.Conn.mu. // the DERPs method acquires magicsock.Conn.mu.
@ -1060,6 +1062,7 @@ func (e *userspaceEngine) getStatus() (*Status, error) {
} }
pr, pw := io.Pipe() pr, pw := io.Pipe()
defer pr.Close() // to unblock writes on error path returns
errc := make(chan error, 1) errc := make(chan error, 1)
go func() { go func() {
@ -1096,9 +1099,9 @@ func (e *userspaceEngine) getStatus() (*Status, error) {
break break
} }
if err != nil { if err != nil {
pr.Close()
return nil, fmt.Errorf("reading from UAPI pipe: %w", err) return nil, fmt.Errorf("reading from UAPI pipe: %w", err)
} }
line = bytes.TrimSuffix(line, singleNewline)
k := line k := line
var v mem.RO var v mem.RO
if i := bytes.IndexByte(line, '='); i != -1 { if i := bytes.IndexByte(line, '='); i != -1 {
@ -1109,7 +1112,7 @@ func (e *userspaceEngine) getStatus() (*Status, error) {
case "public_key": case "public_key":
pk, err := key.NewPublicFromHexMem(v) pk, err := key.NewPublicFromHexMem(v)
if err != nil { if err != nil {
return nil, fmt.Errorf("IpcGetOperation: invalid key %#v", v) return nil, fmt.Errorf("IpcGetOperation: invalid key in line %q", line)
} }
p = &PeerStatus{} p = &PeerStatus{}
pp[wgkey.Key(pk)] = p pp[wgkey.Key(pk)] = p

Loading…
Cancel
Save