mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #6391
Mick Sayson (1): fix(toxext): Protect use of toxext modifying functions
This commit is contained in:
commit
552cb0dc74
|
@ -59,12 +59,14 @@ CoreExt::CoreExt(ExtensionPtr<ToxExt> toxExt_)
|
|||
|
||||
void CoreExt::process()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(toxext_mutex);
|
||||
toxext_iterate(toxExt.get());
|
||||
}
|
||||
|
||||
void CoreExt::onLosslessPacket(uint32_t friendId, const uint8_t* data, size_t length)
|
||||
{
|
||||
if (is_toxext_packet(data, length)) {
|
||||
std::lock_guard<std::mutex> lock(toxext_mutex);
|
||||
toxext_handle_lossless_custom_packet(toxExt.get(), friendId, data, length);
|
||||
}
|
||||
}
|
||||
|
@ -73,11 +75,15 @@ CoreExt::Packet::Packet(
|
|||
ToxExtPacketList* packetList,
|
||||
ToxExtensionMessages* toxExtMessages,
|
||||
uint32_t friendId,
|
||||
std::mutex* toxext_mutex,
|
||||
PacketPassKey)
|
||||
: toxExtMessages(toxExtMessages)
|
||||
: toxext_mutex(toxext_mutex)
|
||||
, toxExtMessages(toxExtMessages)
|
||||
, packetList(packetList)
|
||||
, friendId(friendId)
|
||||
{}
|
||||
{
|
||||
assert(toxext_mutex != nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<ICoreExtPacket> CoreExt::getPacket(uint32_t friendId)
|
||||
{
|
||||
|
@ -85,6 +91,7 @@ std::unique_ptr<ICoreExtPacket> CoreExt::getPacket(uint32_t friendId)
|
|||
toxext_packet_list_create(toxExt.get(), friendId),
|
||||
toxExtMessages.get(),
|
||||
friendId,
|
||||
&toxext_mutex,
|
||||
PacketPassKey{}));
|
||||
}
|
||||
|
||||
|
@ -130,6 +137,8 @@ uint64_t CoreExt::Packet::addExtendedMessage(QString message)
|
|||
|
||||
bool CoreExt::Packet::send()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(*toxext_mutex);
|
||||
|
||||
auto ret = toxext_send(packetList);
|
||||
if (ret != TOXEXT_SUCCESS) {
|
||||
qWarning() << "Failed to send packet";
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <bitset>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
struct Tox;
|
||||
|
@ -86,6 +87,7 @@ public:
|
|||
ToxExtPacketList* packetList,
|
||||
ToxExtensionMessages* toxExtMessages,
|
||||
uint32_t friendId,
|
||||
std::mutex* toxext_mutex,
|
||||
PacketPassKey);
|
||||
|
||||
// Delete copy constructor, we shouldn't be able to copy
|
||||
|
@ -97,16 +99,19 @@ public:
|
|||
packetList = other.packetList;
|
||||
friendId = other.friendId;
|
||||
hasBeenSent = other.hasBeenSent;
|
||||
toxext_mutex = other.toxext_mutex;
|
||||
other.toxExtMessages = nullptr;
|
||||
other.packetList = nullptr;
|
||||
other.friendId = 0;
|
||||
other.hasBeenSent = false;
|
||||
other.toxext_mutex = nullptr;
|
||||
}
|
||||
|
||||
uint64_t addExtendedMessage(QString message) override;
|
||||
|
||||
bool send() override;
|
||||
private:
|
||||
std::mutex* toxext_mutex;
|
||||
bool hasBeenSent = false;
|
||||
// Note: non-owning pointer
|
||||
ToxExtensionMessages* toxExtMessages;
|
||||
|
@ -141,6 +146,7 @@ private:
|
|||
|
||||
CoreExt(ExtensionPtr<ToxExt> toxExt);
|
||||
|
||||
std::mutex toxext_mutex;
|
||||
std::unordered_map<uint32_t, Status::Status> currentStatuses;
|
||||
ExtensionPtr<ToxExt> toxExt;
|
||||
ExtensionPtr<ToxExtensionMessages> toxExtMessages;
|
||||
|
|
Loading…
Reference in New Issue
Block a user