mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-11-01 10:21:59 +00:00
Merge pull request #3393 from jbrazio/fix/static-pool-hardening
Improve null checks and index validation in StaticPoolPacketManager
This commit is contained in:
@@ -44,7 +44,7 @@ mesh::Packet* PacketQueue::get(uint32_t now) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mesh::Packet* PacketQueue::removeByIdx(int i) {
|
mesh::Packet* PacketQueue::removeByIdx(int i) {
|
||||||
if (i >= _num) return NULL; // invalid index
|
if (i < 0 || i >= _num) return NULL; // invalid index
|
||||||
|
|
||||||
mesh::Packet* item = _table[i];
|
mesh::Packet* item = _table[i];
|
||||||
_num--;
|
_num--;
|
||||||
@@ -80,10 +80,14 @@ mesh::Packet* StaticPoolPacketManager::allocNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StaticPoolPacketManager::free(mesh::Packet* packet) {
|
void StaticPoolPacketManager::free(mesh::Packet* packet) {
|
||||||
unused.add(packet, 0, 0);
|
if (packet == NULL) return;
|
||||||
|
if (!unused.add(packet, 0, 0)) {
|
||||||
|
MESH_DEBUG_PRINTLN("free: unused queue full, possible double-free detected");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticPoolPacketManager::queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
void StaticPoolPacketManager::queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) {
|
||||||
|
if (packet == NULL) return;
|
||||||
if (!send_queue.add(packet, priority, scheduled_for)) {
|
if (!send_queue.add(packet, priority, scheduled_for)) {
|
||||||
MESH_DEBUG_PRINTLN("queueOutbound: send queue full, dropping packet");
|
MESH_DEBUG_PRINTLN("queueOutbound: send queue full, dropping packet");
|
||||||
free(packet);
|
free(packet);
|
||||||
@@ -115,6 +119,7 @@ mesh::Packet* StaticPoolPacketManager::removeOutboundByIdx(int i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
||||||
|
if (packet == NULL) return;
|
||||||
if (!rx_queue.add(packet, 0, scheduled_for)) {
|
if (!rx_queue.add(packet, 0, scheduled_for)) {
|
||||||
MESH_DEBUG_PRINTLN("queueInbound: rx queue full, dropping packet");
|
MESH_DEBUG_PRINTLN("queueInbound: rx queue full, dropping packet");
|
||||||
free(packet);
|
free(packet);
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ public:
|
|||||||
bool add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for);
|
bool add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for);
|
||||||
int count() const { return _num; }
|
int count() const { return _num; }
|
||||||
int countBefore(uint32_t now) const;
|
int countBefore(uint32_t now) const;
|
||||||
mesh::Packet* itemAt(int i) const { return _table[i]; }
|
mesh::Packet* itemAt(int i) const {
|
||||||
|
if (i < 0 || i >= _num) return NULL;
|
||||||
|
return _table[i];
|
||||||
|
}
|
||||||
mesh::Packet* removeByIdx(int i);
|
mesh::Packet* removeByIdx(int i);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user