Fix nil pointer deref on uncommon tor errors
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-05-03 10:45:41 -07:00
parent 38eb603dec
commit 4c0148619e
2 changed files with 7 additions and 5 deletions

View File

@ -192,17 +192,22 @@ func (tp *torProvider) Listen(identity connectivity.PrivateKey, port int) (conne
conf := &tor.ListenConf{NoWait: true, Version3: true, Key: identity, RemotePorts: []int{port}, Detach: true, DiscardKey: true, LocalListener: localListener}
os, err := tp.t.Listen(nil, conf)
// Reattach to the old local listener...
// Note: this code probably shouldn't be hit in Cwtch anymore because we purge torrc on restart.
if err != nil && strings.Contains(err.Error(), "550 Unspecified Tor error: Onion address collision") {
log.Errorf("550 Unspecified Tor error: Onion address collision - Recovering, but this probably indicates some weird tor configuration issue...")
os = &tor.OnionService{Tor: tp.t, LocalListener: localListener, ID: onion, Version3: true, Key: bineed255192.FromCryptoPrivateKey(privkey), ClientAuths: make(map[string]string, 0), RemotePorts: []int{port}}
err = nil
}
// Not set in t.Listen if supplied, we want it to handle this however
os.CloseLocalListenerOnClose = true
// Any other errors require an immediate return as os is likely nil...
if err != nil {
return nil, err
}
os.CloseLocalListenerOnClose = true
ols := &onionListenService{os: os, tp: tp}
tp.childListeners[ols.AddressIdentity()] = ols
return ols, nil
@ -218,7 +223,6 @@ func (tp *torProvider) Restart() {
return
}
go tp.restart()
}

View File

@ -45,7 +45,5 @@ func TestTorProvider(t *testing.T) {
acn.Restart()
acn.Restart()
acn.Close()
}