From 8ab0e9993a001814bbcfead4fef1252806e261fa Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 21 Apr 2023 14:21:49 -0700 Subject: [PATCH] Make DelteProfile and ShutdownPeer safe to call twice / with incorrect onion --- app/app.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/app.go b/app/app.go index b9c1b8b..634f245 100644 --- a/app/app.go +++ b/app/app.go @@ -255,6 +255,12 @@ func (app *application) DeleteProfile(onion string, password string) { app.appmutex.Lock() defer app.appmutex.Unlock() + // short circuit to prevent nil-pointer panic if this function is called twice (or incorrectly) + if app.peers[onion] == nil { + log.Errorf("shutdownPeer called with invalid onion %v", onion) + return + } + // allow a blank password to delete "unencrypted" accounts... if password == "" { password = DefactoPasswordForUnencryptedProfiles @@ -477,6 +483,13 @@ func (app *application) ShutdownPeer(onion string) { // shutdownPeer mutex unlocked helper shutdown peer func (app *application) shutdownPeer(onion string) { + + // short circuit to prevent nil-pointer panic if this function is called twice (or incorrectly) + if app.eventBuses[onion] == nil || app.peers[onion] == nil { + log.Errorf("shutdownPeer called with invalid onion %v", onion) + return + } + app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion)) app.eventBuses[onion].Shutdown() delete(app.eventBuses, onion)