mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
conversation: refuse malformed uri
Second part of this fix: https://review.jami.net/c/jami-daemon/+/28337 GitLab: #1721 Change-Id: Ie428a57d89ac3db4e32660735cb3a5b0bf0f5c94
This commit is contained in:
@ -140,8 +140,14 @@ addConversationMember(const std::string& accountId,
|
||||
const std::string& contactUri)
|
||||
{
|
||||
if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
|
||||
if (auto convModule = acc->convModule(true))
|
||||
convModule->addConversationMember(conversationId, contactUri);
|
||||
if (auto convModule = acc->convModule(true)) {
|
||||
dht::InfoHash h(contactUri);
|
||||
if (not h) {
|
||||
JAMI_ERROR("addConversationMember: invalid contact URI `{}`", contactUri);
|
||||
return;
|
||||
}
|
||||
convModule->addConversationMember(conversationId, h);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -150,8 +156,14 @@ removeConversationMember(const std::string& accountId,
|
||||
const std::string& contactUri)
|
||||
{
|
||||
if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
|
||||
if (auto convModule = acc->convModule(true))
|
||||
convModule->removeConversationMember(conversationId, contactUri);
|
||||
if (auto convModule = acc->convModule(true)) {
|
||||
dht::InfoHash h(contactUri);
|
||||
if (not h) {
|
||||
JAMI_ERROR("removeConversationMember: invalid contact URI `{}`", contactUri);
|
||||
return;
|
||||
}
|
||||
convModule->removeConversationMember(conversationId, h);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::map<std::string, std::string>>
|
||||
|
@ -2596,7 +2596,7 @@ ConversationModule::fetchNewCommits(const std::string& peer,
|
||||
|
||||
void
|
||||
ConversationModule::addConversationMember(const std::string& conversationId,
|
||||
const std::string& contactUri,
|
||||
const dht::InfoHash& contactUri,
|
||||
bool sendRequest)
|
||||
{
|
||||
auto conv = pimpl_->getConversation(conversationId);
|
||||
@ -2606,19 +2606,20 @@ ConversationModule::addConversationMember(const std::string& conversationId,
|
||||
}
|
||||
std::unique_lock lk(conv->mtx);
|
||||
|
||||
if (conv->conversation->isMember(contactUri, true)) {
|
||||
JAMI_DEBUG("{:s} is already a member of {:s}, resend invite", contactUri, conversationId);
|
||||
auto contactUriStr = contactUri.toString();
|
||||
if (conv->conversation->isMember(contactUriStr, true)) {
|
||||
JAMI_DEBUG("{:s} is already a member of {:s}, resend invite", contactUriStr, conversationId);
|
||||
// Note: This should not be necessary, but if for whatever reason the other side didn't
|
||||
// join we should not forbid new invites
|
||||
auto invite = conv->conversation->generateInvitation();
|
||||
lk.unlock();
|
||||
pimpl_->sendMsgCb_(contactUri, {}, std::move(invite), 0);
|
||||
pimpl_->sendMsgCb_(contactUriStr, {}, std::move(invite), 0);
|
||||
return;
|
||||
}
|
||||
|
||||
conv->conversation->addMember(
|
||||
contactUri,
|
||||
[this, conv, conversationId, sendRequest, contactUri](bool ok, const std::string& commitId) {
|
||||
contactUriStr,
|
||||
[this, conv, conversationId, sendRequest, contactUriStr](bool ok, const std::string& commitId) {
|
||||
if (ok) {
|
||||
std::unique_lock lk(conv->mtx);
|
||||
pimpl_->sendMessageNotification(*conv->conversation,
|
||||
@ -2627,7 +2628,7 @@ ConversationModule::addConversationMember(const std::string& conversationId,
|
||||
if (sendRequest) {
|
||||
auto invite = conv->conversation->generateInvitation();
|
||||
lk.unlock();
|
||||
pimpl_->sendMsgCb_(contactUri, {}, std::move(invite), 0);
|
||||
pimpl_->sendMsgCb_(contactUriStr, {}, std::move(invite), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -2635,14 +2636,15 @@ ConversationModule::addConversationMember(const std::string& conversationId,
|
||||
|
||||
void
|
||||
ConversationModule::removeConversationMember(const std::string& conversationId,
|
||||
const std::string& contactUri,
|
||||
const dht::InfoHash& contactUri,
|
||||
bool isDevice)
|
||||
{
|
||||
auto contactUriStr = contactUri.toString();
|
||||
if (auto conv = pimpl_->getConversation(conversationId)) {
|
||||
std::lock_guard lk(conv->mtx);
|
||||
if (conv->conversation)
|
||||
return conv->conversation->removeMember(
|
||||
contactUri, isDevice, [this, conversationId](bool ok, const std::string& commitId) {
|
||||
contactUriStr, isDevice, [this, conversationId](bool ok, const std::string& commitId) {
|
||||
if (ok) {
|
||||
pimpl_->sendMessageNotification(conversationId, true, commitId);
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ public:
|
||||
* @param sendRequest If we need to inform the peer (used for tests)
|
||||
*/
|
||||
void addConversationMember(const std::string& conversationId,
|
||||
const std::string& contactUri,
|
||||
const dht::InfoHash& contactUri,
|
||||
bool sendRequest = true);
|
||||
/**
|
||||
* Remove a member from a conversation (this will trigger a member event + new message on success)
|
||||
@ -365,7 +365,7 @@ public:
|
||||
* @param isDevice
|
||||
*/
|
||||
void removeConversationMember(const std::string& conversationId,
|
||||
const std::string& contactUri,
|
||||
const dht::InfoHash& contactUri,
|
||||
bool isDevice = false);
|
||||
/**
|
||||
* Get members
|
||||
|
@ -781,7 +781,7 @@ ConversationTest::testMergeTwoDifferentHeads()
|
||||
auto convId = libjami::startConversation(aliceId);
|
||||
|
||||
auto msgSize = aliceData.messages.size();
|
||||
aliceAccount->convModule()->addConversationMember(convId, carlaUri, false);
|
||||
aliceAccount->convModule()->addConversationMember(convId, dht::InfoHash(carlaUri), false);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return aliceData.messages.size() == msgSize + 1; }));
|
||||
|
||||
// Cp conversations & convInfo
|
||||
|
@ -1105,7 +1105,7 @@ ConversationMembersEventTest::testMemberJoinsNoBadFile()
|
||||
auto convId = libjami::startConversation(aliceId);
|
||||
|
||||
auto aliceMsgSize = aliceData.messages.size();
|
||||
aliceAccount->convModule()->addConversationMember(convId, carlaUri, false);
|
||||
aliceAccount->convModule()->addConversationMember(convId, dht::InfoHash(carlaUri), false);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 5s, [&] { return aliceMsgSize + 1 == aliceData.messages.size(); }));
|
||||
|
||||
// Cp conversations & convInfo
|
||||
@ -1164,7 +1164,7 @@ ConversationMembersEventTest::testMemberAddedNoCertificate()
|
||||
auto convId = libjami::startConversation(aliceId);
|
||||
|
||||
auto aliceMsgSize = aliceData.messages.size();
|
||||
aliceAccount->convModule()->addConversationMember(convId, carlaUri, false);
|
||||
aliceAccount->convModule()->addConversationMember(convId, dht::InfoHash(carlaUri), false);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 5s, [&] { return aliceMsgSize + 1 == aliceData.messages.size(); }));
|
||||
|
||||
// Cp conversations & convInfo
|
||||
@ -1214,7 +1214,7 @@ ConversationMembersEventTest::testMemberJoinsInviteRemoved()
|
||||
auto convId = libjami::startConversation(aliceId);
|
||||
|
||||
auto aliceMsgSize = aliceData.messages.size();
|
||||
aliceAccount->convModule()->addConversationMember(convId, carlaUri, false);
|
||||
aliceAccount->convModule()->addConversationMember(convId, dht::InfoHash(carlaUri), false);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 5s, [&] { return aliceMsgSize + 1 == aliceData.messages.size(); }));
|
||||
|
||||
// Cp conversations & convInfo
|
||||
|
Reference in New Issue
Block a user