Deskbar: Sanitize the usage of BMessage

... especially for SendMessage and SendReply.
* Delete the item's message if AddItem does not return successfully.
* Fixes #11934.

Signed-off-by: Adrien Destugues <[email protected]>
This commit is contained in:
Dario Casalinuovo
2015-04-13 19:11:45 +02:00
committed by Adrien Destugues
parent 9e11c3adb1
commit 0fc30d8934
5 changed files with 38 additions and 25 deletions
+2 -1
View File
@@ -263,7 +263,8 @@ TBarView::MessageReceived(BMessage* message)
// so that I can follow the common pathway // so that I can follow the common pathway
// for adding icons to the tray // for adding icons to the tray
int32 id; int32 id;
AddItem(new BMessage(*message), B_DESKBAR_TRAY, &id); if (AddItem(message, B_DESKBAR_TRAY, &id) == B_OK)
Looper()->DetachCurrentMessage();
break; break;
} }
+10 -6
View File
@@ -39,6 +39,7 @@ All rights reserved.
#include <stdio.h> #include <stdio.h>
#include <Application.h> #include <Application.h>
#include <AutoDeleter.h>
#include <Catalog.h> #include <Catalog.h>
#include <Directory.h> #include <Directory.h>
#include <FindDirectory.h> #include <FindDirectory.h>
@@ -516,15 +517,18 @@ TBarWindow::AddItem(BMessage* message)
BMessage reply; BMessage reply;
status_t err = B_ERROR; status_t err = B_ERROR;
BMessage archivedView; BMessage* archivedView = new BMessage();
if (message->FindMessage("view", &archivedView) == B_OK) { ObjectDeleter<BMessage> deleter(archivedView);
if (message->FindMessage("view", archivedView) == B_OK) {
#if SHELF_AWARE #if SHELF_AWARE
message->FindInt32("shelf", &shelf); message->FindInt32("shelf", &shelf);
#endif #endif
BMessage* archive = new BMessage(archivedView); err = fBarView->AddItem(archivedView, shelf, &id);
err = fBarView->AddItem(archive, shelf, &id); if (err == B_OK) {
if (err < B_OK) // Detach the deleter since AddReplicant is taking ownership
delete archive; // on success. This should be changed on server side.
deleter.Detach();
}
} else if (message->FindRef("addon", &ref) == B_OK) { } else if (message->FindRef("addon", &ref) == B_OK) {
BEntry entry(&ref); BEntry entry(&ref);
err = entry.InitCheck(); err = entry.InitCheck();
+12 -11
View File
@@ -337,12 +337,12 @@ TReplicantTray::MessageReceived(BMessage* message)
bool showDayOfWeek = fTime->ShowDayOfWeek(); bool showDayOfWeek = fTime->ShowDayOfWeek();
bool showTimeZone = fTime->ShowTimeZone(); bool showTimeZone = fTime->ShowTimeZone();
BMessage* reply = new BMessage(kGetClockSettings); BMessage reply(kGetClockSettings);
reply->AddBool("showClock", showClock); reply.AddBool("showClock", showClock);
reply->AddBool("showSeconds", showSeconds); reply.AddBool("showSeconds", showSeconds);
reply->AddBool("showDayOfWeek", showDayOfWeek); reply.AddBool("showDayOfWeek", showDayOfWeek);
reply->AddBool("showTimeZone", showTimeZone); reply.AddBool("showTimeZone", showTimeZone);
message->SendReply(reply); message->SendReply(&reply);
break; break;
} }
@@ -451,9 +451,9 @@ TReplicantTray::ShowHideTime()
// Send a message to Time preferences telling it to update // Send a message to Time preferences telling it to update
BMessenger messenger("application/x-vnd.Haiku-Time"); BMessenger messenger("application/x-vnd.Haiku-Time");
BMessage* message = new BMessage(kShowHideTime); BMessage message(kShowHideTime);
message->AddBool("showClock", showClock); message.AddBool("showClock", showClock);
messenger.SendMessage(message); messenger.SendMessage(&message);
} }
@@ -673,8 +673,9 @@ TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings)
view->Archive(data); view->Archive(data);
delete view; delete view;
AddIcon(data, id, &ref); // add the rep; adds info to list
// add the rep; adds info to list if (AddIcon(data, id, &ref) != B_OK)
delete data;
if (addToSettings) { if (addToSettings) {
fAddOnSettings.AddString(kReplicantPathField, path.Path()); fAddOnSettings.AddString(kReplicantPathField, path.Path());
+2 -2
View File
@@ -195,8 +195,8 @@ TTimeView::MessageReceived(BMessage* message)
be_roster->Launch("application/x-vnd.Haiku-Time"); be_roster->Launch("application/x-vnd.Haiku-Time");
// tell Time preflet to switch to the clock tab // tell Time preflet to switch to the clock tab
BMessenger messenger("application/x-vnd.Haiku-Time"); BMessenger messenger("application/x-vnd.Haiku-Time");
BMessage* switchToClock = new BMessage('SlCk'); BMessage switchToClock('SlCk');
messenger.SendMessage(switchToClock); messenger.SendMessage(&switchToClock);
break; break;
} }
+12 -5
View File
@@ -16,6 +16,7 @@
#include <pthread.h> #include <pthread.h>
#include <AutoDeleter.h>
#include <AutoLock.h> #include <AutoLock.h>
#include <Beep.h> #include <Beep.h>
#include <Dragger.h> #include <Dragger.h>
@@ -1178,13 +1179,19 @@ BShelf::_InitData(BEntry *entry, BDataIO *stream, BView *view,
genCount = 1; genCount = 1;
BMessage replicant; BMessage replicant;
BMessage *replmsg = NULL; for (int32 i = 0; archive.FindMessage("replicant", i, &replicant)
for (int32 i = 0; archive.FindMessage("replicant", i, &replicant) == B_OK; i++) { == B_OK; i++) {
BPoint point; BPoint point;
replmsg = new BMessage(); BMessage *replMsg = new BMessage();
ObjectDeleter<BMessage> deleter(replMsg);
replicant.FindPoint("position", &point); replicant.FindPoint("position", &point);
replicant.FindMessage("message", replmsg); if (replicant.FindMessage("message", replMsg) == B_OK)
AddReplicant(replmsg, point); if (AddReplicant(replMsg, point) == B_OK) {
// Detach the deleter since AddReplicant is taking
// ownership on success. In R2 API this should be
// changed to take always ownership on the message.
deleter.Detach();
}
} }
} }
} }