From eca86a00ae913c3c91ddfb55a67d3c5b2318fab8 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 26 Jun 2024 16:35:50 -0400 Subject: [PATCH] Tracker: Add a try/catch around ModelMenuItem's creation in AddOneAddOn. ModelMenuItem can throw exceptions if its Model fails to initialize, and even though we pass a Model in directly, copying the Model results in opening the underlying file again, which of course may fail if something changed since our Model was created. While at it, remove the return value, since it isn't used anywhere. Should fix #18905. --- src/kits/tracker/ContainerWindow.cpp | 16 ++++++++++------ src/kits/tracker/ContainerWindow.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/kits/tracker/ContainerWindow.cpp b/src/kits/tracker/ContainerWindow.cpp index f654139800..04b9641616 100644 --- a/src/kits/tracker/ContainerWindow.cpp +++ b/src/kits/tracker/ContainerWindow.cpp @@ -237,7 +237,7 @@ end: } -static bool +static void AddOneAddOn(const Model* model, const char* name, uint32 shortcut, uint32 modifiers, bool primary, void* context, BContainerWindow* window, BMenu* menu) @@ -247,8 +247,14 @@ AddOneAddOn(const Model* model, const char* name, uint32 shortcut, BMessage* message = new BMessage(kLoadAddOn); message->AddRef("refs", model->EntryRef()); - ModelMenuItem* item = new ModelMenuItem(model, name, message, - (char)shortcut, modifiers); + ModelMenuItem* item; + try { + item = new ModelMenuItem(model, name, message, + (char)shortcut, modifiers); + } catch (...) { + delete message; + return; + } const entry_ref* addOnRef = model->EntryRef(); AddOnMenuGenerate(addOnRef, menu, window); @@ -257,8 +263,6 @@ AddOneAddOn(const Model* model, const char* name, uint32 shortcut, params->primaryList->AddItem(item); else params->secondaryList->AddItem(item); - - return false; } @@ -2891,7 +2895,7 @@ BContainerWindow::AddTrashContextMenus(BMenu* menu) void -BContainerWindow::EachAddOn(bool (*eachAddOn)(const Model*, const char*, +BContainerWindow::EachAddOn(void (*eachAddOn)(const Model*, const char*, uint32 shortcut, uint32 modifiers, bool primary, void* context, BContainerWindow* window, BMenu* menu), void* passThru, BStringList& mimeTypes, BMenu* menu) diff --git a/src/kits/tracker/ContainerWindow.h b/src/kits/tracker/ContainerWindow.h index 7103307b76..c1234733b1 100644 --- a/src/kits/tracker/ContainerWindow.h +++ b/src/kits/tracker/ContainerWindow.h @@ -268,7 +268,7 @@ protected: const char*); void LoadAddOn(BMessage*); - void EachAddOn(bool (*)(const Model*, const char*, uint32 shortcut, + void EachAddOn(void (*)(const Model*, const char*, uint32 shortcut, uint32 modifiers, bool primary, void*, BContainerWindow*, BMenu*), void*, BStringList&, BMenu*);