Commit 79330e5d authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud

jamiaccount: fix deviceListMutex_ deadlock

findCertificate can use an already locked (by onReceiveDeviceSync)
mutex. This shouldn't be the case.

Change-Id: I67a323adbe1b7c2eb6bf451ac5bdcd5d413a8dbe
Gitlab: #120
parent e7e33a53
......@@ -2305,9 +2305,10 @@ JamiAccount::doRegister_()
JAMI_WARN("Can't find certificate for device %s", sync.from.toString().c_str());
return;
}
std::lock_guard<std::mutex> lock(deviceListMutex_);
std::unique_lock<std::mutex> lock(deviceListMutex_);
if (not foundAccountDevice(cert))
return;
lock.unlock();
onReceiveDeviceSync(std::move(sync));
});
......@@ -3319,15 +3320,19 @@ JamiAccount::syncDevices()
void
JamiAccount::onReceiveDeviceSync(DeviceSync&& sync)
{
auto it = knownDevices_.find(sync.from);
if (it == knownDevices_.end()) {
JAMI_WARN("[Account %s] dropping sync data from unknown device", getAccountID().c_str());
return;
}
auto sync_date = clock::time_point(clock::duration(sync.date));
if (it->second.last_sync >= sync_date) {
JAMI_DBG("[Account %s] dropping outdated sync data", getAccountID().c_str());
return;
{
std::lock_guard<std::mutex> lock(deviceListMutex_);
auto it = knownDevices_.find(sync.from);
if (it == knownDevices_.end()) {
JAMI_WARN("[Account %s] dropping sync data from unknown device", getAccountID().c_str());
return;
}
if (it->second.last_sync >= sync_date) {
JAMI_DBG("[Account %s] dropping outdated sync data", getAccountID().c_str());
return;
}
it->second.last_sync = sync_date;
}
// Sync known devices
......@@ -3340,7 +3345,10 @@ JamiAccount::onReceiveDeviceSync(DeviceSync&& sync)
foundAccountDevice(crt, d.second);
});
}
saveKnownDevices();
{
std::lock_guard<std::mutex> lock(deviceListMutex_);
saveKnownDevices();
}
// Sync contacts
for (const auto& peer : sync.peers)
......@@ -3351,7 +3359,6 @@ JamiAccount::onReceiveDeviceSync(DeviceSync&& sync)
for (const auto& tr : sync.trust_requests)
onTrustRequest(tr.first, tr.second.device, tr.second.received, false, {});
it->second.last_sync = sync_date;
}
void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment