From b5d913e2d725b1bcd7d9b47c244adbbbfbb1d053 Mon Sep 17 00:00:00 2001 From: Benjamin Reis <benjamin.reis@belledonne-communications.com> Date: Mon, 4 Feb 2019 11:37:30 +0100 Subject: [PATCH] add try catch --- .../local-conference-list-event-handler.cpp | 15 ++++++++--- .../remote-conference-event-handler.cpp | 8 +++++- .../remote-conference-list-event-handler.cpp | 25 +++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/conference/handlers/local-conference-list-event-handler.cpp b/src/conference/handlers/local-conference-list-event-handler.cpp index 95675250c3..0a2fdc4f07 100644 --- a/src/conference/handlers/local-conference-list-event-handler.cpp +++ b/src/conference/handlers/local-conference-list-event-handler.cpp @@ -108,10 +108,17 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con bool noContent = true; list<Content> contents; istringstream data(xmlBody); - unique_ptr<Xsd::ResourceLists::ResourceLists> rl(Xsd::ResourceLists::parseResourceLists( - data, - Xsd::XmlSchema::Flags::dont_validate - )); + unique_ptr<Xsd::ResourceLists::ResourceLists> rl; + try { + rl = Xsd::ResourceLists::parseResourceLists( + data, + Xsd::XmlSchema::Flags::dont_validate + ); + } catch (const exception &) { + lError() << "Error while parsing subscribe body for conferences asked by: " << participantAddr; + return; + } + for (const auto &l : rl->getList()) { for (const auto &entry : l.getEntry()) { Address addr(entry.getUri()); diff --git a/src/conference/handlers/remote-conference-event-handler.cpp b/src/conference/handlers/remote-conference-event-handler.cpp index 7f265116f5..b9a1a8758d 100644 --- a/src/conference/handlers/remote-conference-event-handler.cpp +++ b/src/conference/handlers/remote-conference-event-handler.cpp @@ -46,7 +46,13 @@ using namespace Xsd::ConferenceInfo; void RemoteConferenceEventHandlerPrivate::simpleNotifyReceived (const string &xmlBody) { istringstream data(xmlBody); - unique_ptr<ConferenceType> confInfo = parseConferenceInfo(data, Xsd::XmlSchema::Flags::dont_validate); + unique_ptr<ConferenceType> confInfo; + try { + confInfo = parseConferenceInfo(data, Xsd::XmlSchema::Flags::dont_validate); + } catch (const exception &) { + lError() << "Error while parsing conference notify for: " << conferenceId; + return; + } IdentityAddress entityAddress(confInfo->getEntity().c_str()); if (entityAddress != conferenceId.getPeerAddress()) diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index f4edbc6c40..ab823858b5 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -139,7 +139,16 @@ void RemoteConferenceListEventHandler::notifyReceived (const Content *notifyCont // Simple notify received directly from a chat-room const string &xmlBody = notifyContent->getBodyAsUtf8String(); istringstream data(xmlBody); - unique_ptr<Xsd::ConferenceInfo::ConferenceType> confInfo = Xsd::ConferenceInfo::parseConferenceInfo(data, Xsd::XmlSchema::Flags::dont_validate); + unique_ptr<Xsd::ConferenceInfo::ConferenceType> confInfo; + try { + confInfo = Xsd::ConferenceInfo::parseConferenceInfo( + data, + Xsd::XmlSchema::Flags::dont_validate + ); + } catch (const exception &) { + lError() << "Error while parsing conference-info in conferences notify"; + return; + } IdentityAddress entityAddress(confInfo->getEntity().c_str()); ConferenceId id(entityAddress, local); @@ -210,11 +219,17 @@ void RemoteConferenceListEventHandler::removeHandler (RemoteConferenceEventHandl map<string, IdentityAddress> RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const { istringstream data(xmlBody); - unique_ptr<Xsd::Rlmi::List> rlmi(Xsd::Rlmi::parseList( - data, - Xsd::XmlSchema::Flags::dont_validate - )); map<string, IdentityAddress> addresses; + unique_ptr<Xsd::Rlmi::List> rlmi; + try { + rlmi = Xsd::Rlmi::parseList( + data, + Xsd::XmlSchema::Flags::dont_validate + ); + } catch (const exception &) { + lError() << "Error while parsing RLMI in conferences notify"; + return addresses; + } for (const auto &resource : rlmi->getResource()) { if (resource.getInstance().empty()) continue; -- GitLab