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()
|
void CoreExt::process()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(toxext_mutex);
|
||||||
toxext_iterate(toxExt.get());
|
toxext_iterate(toxExt.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreExt::onLosslessPacket(uint32_t friendId, const uint8_t* data, size_t length)
|
void CoreExt::onLosslessPacket(uint32_t friendId, const uint8_t* data, size_t length)
|
||||||
{
|
{
|
||||||
if (is_toxext_packet(data, 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);
|
toxext_handle_lossless_custom_packet(toxExt.get(), friendId, data, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,11 +75,15 @@ CoreExt::Packet::Packet(
|
||||||
ToxExtPacketList* packetList,
|
ToxExtPacketList* packetList,
|
||||||
ToxExtensionMessages* toxExtMessages,
|
ToxExtensionMessages* toxExtMessages,
|
||||||
uint32_t friendId,
|
uint32_t friendId,
|
||||||
|
std::mutex* toxext_mutex,
|
||||||
PacketPassKey)
|
PacketPassKey)
|
||||||
: toxExtMessages(toxExtMessages)
|
: toxext_mutex(toxext_mutex)
|
||||||
|
, toxExtMessages(toxExtMessages)
|
||||||
, packetList(packetList)
|
, packetList(packetList)
|
||||||
, friendId(friendId)
|
, friendId(friendId)
|
||||||
{}
|
{
|
||||||
|
assert(toxext_mutex != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<ICoreExtPacket> CoreExt::getPacket(uint32_t friendId)
|
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),
|
toxext_packet_list_create(toxExt.get(), friendId),
|
||||||
toxExtMessages.get(),
|
toxExtMessages.get(),
|
||||||
friendId,
|
friendId,
|
||||||
|
&toxext_mutex,
|
||||||
PacketPassKey{}));
|
PacketPassKey{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +137,8 @@ uint64_t CoreExt::Packet::addExtendedMessage(QString message)
|
||||||
|
|
||||||
bool CoreExt::Packet::send()
|
bool CoreExt::Packet::send()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(*toxext_mutex);
|
||||||
|
|
||||||
auto ret = toxext_send(packetList);
|
auto ret = toxext_send(packetList);
|
||||||
if (ret != TOXEXT_SUCCESS) {
|
if (ret != TOXEXT_SUCCESS) {
|
||||||
qWarning() << "Failed to send packet";
|
qWarning() << "Failed to send packet";
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
struct Tox;
|
struct Tox;
|
||||||
|
@ -86,6 +87,7 @@ public:
|
||||||
ToxExtPacketList* packetList,
|
ToxExtPacketList* packetList,
|
||||||
ToxExtensionMessages* toxExtMessages,
|
ToxExtensionMessages* toxExtMessages,
|
||||||
uint32_t friendId,
|
uint32_t friendId,
|
||||||
|
std::mutex* toxext_mutex,
|
||||||
PacketPassKey);
|
PacketPassKey);
|
||||||
|
|
||||||
// Delete copy constructor, we shouldn't be able to copy
|
// Delete copy constructor, we shouldn't be able to copy
|
||||||
|
@ -97,16 +99,19 @@ public:
|
||||||
packetList = other.packetList;
|
packetList = other.packetList;
|
||||||
friendId = other.friendId;
|
friendId = other.friendId;
|
||||||
hasBeenSent = other.hasBeenSent;
|
hasBeenSent = other.hasBeenSent;
|
||||||
|
toxext_mutex = other.toxext_mutex;
|
||||||
other.toxExtMessages = nullptr;
|
other.toxExtMessages = nullptr;
|
||||||
other.packetList = nullptr;
|
other.packetList = nullptr;
|
||||||
other.friendId = 0;
|
other.friendId = 0;
|
||||||
other.hasBeenSent = false;
|
other.hasBeenSent = false;
|
||||||
|
other.toxext_mutex = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t addExtendedMessage(QString message) override;
|
uint64_t addExtendedMessage(QString message) override;
|
||||||
|
|
||||||
bool send() override;
|
bool send() override;
|
||||||
private:
|
private:
|
||||||
|
std::mutex* toxext_mutex;
|
||||||
bool hasBeenSent = false;
|
bool hasBeenSent = false;
|
||||||
// Note: non-owning pointer
|
// Note: non-owning pointer
|
||||||
ToxExtensionMessages* toxExtMessages;
|
ToxExtensionMessages* toxExtMessages;
|
||||||
|
@ -141,6 +146,7 @@ private:
|
||||||
|
|
||||||
CoreExt(ExtensionPtr<ToxExt> toxExt);
|
CoreExt(ExtensionPtr<ToxExt> toxExt);
|
||||||
|
|
||||||
|
std::mutex toxext_mutex;
|
||||||
std::unordered_map<uint32_t, Status::Status> currentStatuses;
|
std::unordered_map<uint32_t, Status::Status> currentStatuses;
|
||||||
ExtensionPtr<ToxExt> toxExt;
|
ExtensionPtr<ToxExt> toxExt;
|
||||||
ExtensionPtr<ToxExtensionMessages> toxExtMessages;
|
ExtensionPtr<ToxExtensionMessages> toxExtMessages;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user