From d72f06fae8f0b62a6904d3b84c8589aea16b775c Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Fri, 3 Feb 2017 14:14:31 -0500 Subject: [PATCH] ring account: fix crash when archive is invalid Commit b335c13f5c makes RingAccount::readArchive() throw exceptions to return failure to read/parse an archive file. This patch makes sure that all calls to this method handles correctly these exceptions. Change-Id: I7c9bb33b4207c3767e6c0613b71e84bc5c0c9b69 --- src/ringdht/ringaccount.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index 01e84a3c20..d57ade141f 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -1122,14 +1122,18 @@ RingAccount::revokeDevice(const std::string& password, const std::string& device { // shared_ptr of future auto fa = ThreadPool::instance().getShared<ArchiveContent>( - std::bind(&RingAccount::readArchive, this, password) - ); + [this, password] { return readArchive(password); }); auto sthis = shared(); findCertificate(dht::InfoHash(device), [fa,sthis,password](const std::shared_ptr<dht::crypto::Certificate>& crt) mutable { sthis->foundAccountDevice(crt); - ArchiveContent a = fa->get(); + ArchiveContent a; + try { + a = fa->get(); + } catch (...) { + return; + } // Add revoked device to the revocation list and resign it if (not a.revoked) a.revoked = std::make_shared<decltype(a.revoked)::element_type>(); @@ -1363,7 +1367,12 @@ RingAccount::updateCertificates(ArchiveContent& archive, dht::crypto::Identity& bool RingAccount::migrateAccount(const std::string& pwd) { - auto archive = readArchive(pwd); + ArchiveContent archive; + try { + archive = readArchive(pwd); + } catch (...) { + return false; + } if (updateCertificates(archive, identity_)) { std::tie(tlsPrivateKeyFile_, tlsCertificateFile_) = saveIdentity(identity_, idPath_ + DIR_SEPARATOR_STR "ring_device"); -- GitLab