From 6ae61bbb40a722472a60ec8555374c320f02e24a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Ram=C3=B3n=20Guevara?= Date: Thu, 26 Nov 2026 18:00:24 +0100 Subject: [PATCH] fix bug where a login from a new identity silently removes an admin --- examples/simple_repeater/MyMesh.cpp | 1 + examples/simple_room_server/MyMesh.cpp | 2 ++ examples/simple_sensor/SensorMesh.cpp | 1 + src/helpers/ClientACL.cpp | 4 +++- src/helpers/ClientACL.h | 2 +- 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 9501ba92..d0388f67 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -123,6 +123,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr } client = acl.putClient(sender, 0); // add to contacts (if not already known) + if (client == NULL) return 0; if (sender_timestamp <= client->last_timestamp) { MESH_DEBUG_PRINTLN("Possible login replay attack!"); return 0; // FATAL: client table is full -OR- replay attack diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index c1a6b09f..6289de81 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -357,6 +357,8 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m } client = acl.putClient(sender, 0); // add to known clients (if not already known) + if (client == NULL) return; + if (sender_timestamp <= client->last_timestamp) { MESH_DEBUG_PRINTLN("possible replay attack!"); return; diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 4916ddcd..8a68381a 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -383,6 +383,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* } client = acl.putClient(sender, PERM_RECV_ALERTS_HI | PERM_RECV_ALERTS_LO); // add to contacts (if not already known) + if (client == NULL) return 0; if (sender_timestamp <= client->last_timestamp) { MESH_DEBUG_PRINTLN("Possible login replay attack!"); return 0; // FATAL: client table is full -OR- replay attack diff --git a/src/helpers/ClientACL.cpp b/src/helpers/ClientACL.cpp index 12823827..9e925523 100644 --- a/src/helpers/ClientACL.cpp +++ b/src/helpers/ClientACL.cpp @@ -96,7 +96,7 @@ ClientInfo* ClientACL::getClient(const uint8_t* pubkey, int key_len) { ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) { uint32_t min_time = 0xFFFFFFFF; - ClientInfo* oldest = &clients[MAX_CLIENTS - 1]; + ClientInfo* oldest = NULL; for (int i = 0; i < num_clients; i++) { if (id.matches(clients[i].id)) return &clients[i]; // already known if (!clients[i].isAdmin() && clients[i].last_activity < min_time) { @@ -109,6 +109,7 @@ ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) { if (num_clients < MAX_CLIENTS) { c = &clients[num_clients++]; } else { + if (oldest == NULL) return NULL; // every entry is an admin, so don't evict c = oldest; // evict least active contact } memset(c, 0, sizeof(*c)); @@ -135,6 +136,7 @@ bool ClientACL::applyPermissions(const mesh::LocalIdentity& self_id, const uint8 mesh::Identity id(pubkey); c = putClient(id, 0); + if (c == NULL) return false; // couldn't put client c->permissions = perms; // update their permissions self_id.calcSharedSecret(c->shared_secret, pubkey); diff --git a/src/helpers/ClientACL.h b/src/helpers/ClientACL.h index 9938bc1e..5e2171b3 100644 --- a/src/helpers/ClientACL.h +++ b/src/helpers/ClientACL.h @@ -60,7 +60,7 @@ public: bool clear(); ClientInfo* getClient(const uint8_t* pubkey, int key_len); - ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms); + ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms); // returns NULL if table is full and all entries are admins bool applyPermissions(const mesh::LocalIdentity& self_id, const uint8_t* pubkey, int key_len, uint8_t perms); int getNumClients() const { return num_clients; }