From 8a3cf4c95a306cedabc9010d041facebcb733923 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee <elv1313@gmail.com> Date: Fri, 23 Jun 2017 04:11:39 -0400 Subject: [PATCH] ringaccount: Prevent exiting due to an uncaught exception. Lookup buddy '>>>>>' and dring would restart. I also added another message in another instance to have a more relevant error message. This has been found by some fuzzing. Change-Id: I484c6449f010567e78dda8e0ae0c4863c7b9ce65 --- src/ringdht/ringaccount.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index 66698fb21a..70fbd6a1ca 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -2016,7 +2016,18 @@ RingAccount::trackBuddyPresence(const std::string& buddy_id) return; } std::weak_ptr<RingAccount> weak_this = std::static_pointer_cast<RingAccount>(shared_from_this()); - auto h = dht::InfoHash(parseRingUri(buddy_id)); + + std::string buddyUri; + + try { + buddyUri = parseRingUri(buddy_id); + } + catch (...) { + RING_ERR("Failed to track a buddy due to an invalid URI %s", buddy_id.c_str()); + return; + } + + auto h = dht::InfoHash(buddyUri); auto buddy_infop = trackedBuddies_.emplace(h, decltype(trackedBuddies_)::mapped_type {h}); if (buddy_infop.second) { auto& buddy_info = buddy_infop.first->second; @@ -3282,7 +3293,17 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string, return; } - auto toUri = parseRingUri(to); + std::string toUri; + + try { + toUri = parseRingUri(to); + } + catch (...) { + RING_ERR("Failed to send a text message due to an invalid URI %s", to.c_str()); + messageEngine_.onMessageSent(token, false); + return; + } + auto toH = dht::InfoHash(toUri); auto now = clock::to_time_t(clock::now()); -- GitLab