From 374ebf0f8c32c4fd8758af4b8381ac5cff0d151c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 5 Feb 2011 16:56:47 +0100 Subject: Don't crash when receiving null roster payload. diff --git a/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp index debbd50..22a55d4 100644 --- a/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp +++ b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp @@ -6,12 +6,13 @@ #include #include +#include #include "Swiften/Roster/XMPPRosterController.h" #include "Swiften/Elements/Payload.h" #include "Swiften/Elements/RosterItemPayload.h" #include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Queries/DummyIQChannel.h" +#include "Swiften/Client/DummyStanzaChannel.h" #include "Swiften/Queries/IQRouter.h" #include "Swiften/Roster/XMPPRosterImpl.h" @@ -19,6 +20,7 @@ using namespace Swift; class XMPPRosterControllerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(XMPPRosterControllerTest); + CPPUNIT_TEST(testGet_EmptyResponse); CPPUNIT_TEST(testAdd); CPPUNIT_TEST(testModify); CPPUNIT_TEST(testRemove); @@ -26,7 +28,7 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { public: void setUp() { - channel_ = new DummyIQChannel(); + channel_ = new DummyStanzaChannel(); router_ = new IQRouter(channel_); xmppRoster_ = new XMPPRosterImpl(); } @@ -37,6 +39,14 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { delete channel_; } + void testGet_EmptyResponse() { + XMPPRosterController controller(router_, xmppRoster_); + + controller.requestRoster(); + + channel_->onIQReceived(IQ::createResult(JID("baz@fum.com/dum"), channel_->sentStanzas[0]->getID(), boost::shared_ptr())); + } + void testAdd() { XMPPRosterController controller(router_, xmppRoster_); @@ -74,7 +84,7 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture { } private: - DummyIQChannel* channel_; + DummyStanzaChannel* channel_; IQRouter* router_; XMPPRosterImpl* xmppRoster_; }; diff --git a/Swiften/Roster/XMPPRosterController.cpp b/Swiften/Roster/XMPPRosterController.cpp index 62bebc3..909ef8e 100644 --- a/Swiften/Roster/XMPPRosterController.cpp +++ b/Swiften/Roster/XMPPRosterController.cpp @@ -39,12 +39,14 @@ void XMPPRosterController::requestRoster() { } void XMPPRosterController::handleRosterReceived(boost::shared_ptr rosterPayload) { - foreach(const RosterItemPayload& item, rosterPayload->getItems()) { - //Don't worry about the updated case, the XMPPRoster sorts that out. - if (item.getSubscription() == RosterItemPayload::Remove) { - xmppRoster_->removeContact(item.getJID()); - } else { - xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription()); + if (rosterPayload) { + foreach(const RosterItemPayload& item, rosterPayload->getItems()) { + //Don't worry about the updated case, the XMPPRoster sorts that out. + if (item.getSubscription() == RosterItemPayload::Remove) { + xmppRoster_->removeContact(item.getJID()); + } else { + xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription()); + } } } } diff --git a/Swiften/Roster/XMPPRosterController.h b/Swiften/Roster/XMPPRosterController.h index dedf090..073a233 100644 --- a/Swiften/Roster/XMPPRosterController.h +++ b/Swiften/Roster/XMPPRosterController.h @@ -26,6 +26,7 @@ namespace Swift { void requestRoster(); + private: void handleRosterReceived(boost::shared_ptr rosterPayload); private: -- cgit v0.10.2-6-g49f6