fix(chat): bound diagnostic counters and invalid mute request parsing
This commit is contained in:
1 parent
c6dcf1ac13
commit
5a9236ebbf
2 files changed
+17
-10
No files matched your search
@@ -256,6 +256,8 @@ done:
|
||||
}
|
||||
|
||||
int chat_core_get_member_list(struct UTUN_INSTANCE* inst, const char* ch_id, uint8_t** out, int* count) {
|
||||
if (out) *out = NULL;
|
||||
if (count) *count = 0;
|
||||
if (!out || !count) { DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "member snapshot: null output"); return -1; }
|
||||
return member_query(inst, ch_id, 0, 0, out, count);
|
||||
}
|
||||
@@ -297,7 +299,7 @@ void chat_core_toggle_member_radio_mute_trampoline(void* arg) {
|
||||
if (!req) { DEBUG_ERROR(DEBUG_CATEGORY_RADIO, "radio: null member mute request"); return; }
|
||||
int rc = chat_core_toggle_member_radio_mute(req->inst, req->ch_id, req->node_id);
|
||||
uint8_t result[17];
|
||||
mf_put64(result, strtoull(req->ch_id, NULL, 10)); mf_put64(result + 8, req->node_id); result[16] = rc == 0;
|
||||
mf_put64(result, chat_channel_id(req->ch_id)); mf_put64(result + 8, req->node_id); result[16] = rc == 0;
|
||||
chat_event_post(req->inst, CHAT_EVT_RADIO_MUTE_RESULT, result, sizeof(result));
|
||||
u_free(req);
|
||||
}
|
||||
|
||||
+14
-9
@@ -63,10 +63,6 @@ static struct address_profile_text link_address_profile_text(const struct ETCP_L
|
||||
return result;
|
||||
}
|
||||
|
||||
static void get_node_name(struct UTUN_INSTANCE* inst, uint64_t node_id, char* out, size_t sz) {
|
||||
chat_core_get_node_name(inst, node_id, out, sz);
|
||||
}
|
||||
|
||||
static void chat_core_collect_status(struct UTUN_INSTANCE* inst) {
|
||||
char buf[96]; int off = 0; struct strbuf text = strbuf_new();
|
||||
|
||||
@@ -125,7 +121,7 @@ static void chat_core_collect_status(struct UTUN_INSTANCE* inst) {
|
||||
snprintf(peerhex, sizeof(peerhex), "%04llX", (unsigned long long)(pid & 0xFFFF));
|
||||
|
||||
char peername[64];
|
||||
get_node_name(inst, pid, peername, sizeof(peername));
|
||||
chat_core_get_node_name(inst, pid, peername, sizeof(peername));
|
||||
|
||||
if (peername[0])
|
||||
STATUS_APPEND( "[%s]→[%s] %s ETCP:%s%s(%dL)\n",
|
||||
@@ -210,7 +206,7 @@ static void collect_conn_list(struct UTUN_INSTANCE* inst) {
|
||||
memcpy(p, &inflight_kb, 2); p += 2;
|
||||
|
||||
char name[32]; memset(name, 0, 32);
|
||||
get_node_name(inst, ce->peer_node_id, name, 31);
|
||||
chat_core_get_node_name(inst, ce->peer_node_id, name, 31);
|
||||
if (!name[0]) snprintf(name, 32, "%016llX", (unsigned long long)ce->peer_node_id);
|
||||
memcpy(p, name, 32); p += 32;
|
||||
}
|
||||
@@ -244,7 +240,7 @@ static void collect_conn_metrics(struct UTUN_INSTANCE* inst, uint64_t peer_node_
|
||||
struct ETCP_CONN* conn = ce->conn;
|
||||
uint64_t my_id = inst->node_id;
|
||||
|
||||
char peername[64]; get_node_name(inst, peer_node_id, peername, sizeof(peername));
|
||||
char peername[64]; chat_core_get_node_name(inst, peer_node_id, peername, sizeof(peername));
|
||||
if (!peername[0]) snprintf(peername, sizeof(peername), "%016llX", (unsigned long long)peer_node_id);
|
||||
|
||||
int is_server = conn->links ? conn->links->is_server : -1;
|
||||
@@ -470,7 +466,7 @@ static void collect_member_detail(const struct chat_member_detail_req* req) {
|
||||
if (conn->links_up) flags |= 2;
|
||||
if (conn->initialized) flags |= 4;
|
||||
}
|
||||
uint16_t own_tcp_active = 0;
|
||||
uint32_t own_tcp_active = 0;
|
||||
if (node_id == inst->node_id) {
|
||||
if (inst->connections) {
|
||||
for (struct ll_entry* e = inst->connections->head; e; e = e->next) {
|
||||
@@ -490,6 +486,10 @@ static void collect_member_detail(const struct chat_member_detail_req* req) {
|
||||
}
|
||||
|
||||
uint8_t link_count = 0;
|
||||
if (own_tcp_active > UINT16_MAX) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, "member detail: active TCP count exceeds wire limit=%u", own_tcp_active);
|
||||
own_tcp_active = UINT16_MAX;
|
||||
}
|
||||
for (struct ETCP_LINK* lk = conn ? conn->links : NULL; lk && link_count < CHAT_MEMBER_DETAIL_MAX_LINKS; lk = lk->next)
|
||||
link_count++;
|
||||
|
||||
@@ -554,7 +554,7 @@ static void collect_member_detail(const struct chat_member_detail_req* req) {
|
||||
const struct sockaddr_storage* sa = s->interface_addr.ss_family ? &s->interface_addr : &s->local_addr;
|
||||
if (sa->ss_family == AF_INET) sp = ntohs(((const struct sockaddr_in*)sa)->sin_port);
|
||||
else if (sa->ss_family == AF_INET6) sp = ntohs(((const struct sockaddr_in6*)sa)->sin6_port);
|
||||
uint16_t lu = 0, ld = 0;
|
||||
uint32_t lu = 0, ld = 0;
|
||||
{ struct ll_entry* e = inst->connections ? inst->connections->head : NULL;
|
||||
for (; e; e = e->next) {
|
||||
struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data;
|
||||
@@ -572,6 +572,11 @@ static void collect_member_detail(const struct chat_member_detail_req* req) {
|
||||
}
|
||||
}
|
||||
char ifname[38] = {0}; sock_ifname(s->name, ifname, sizeof(ifname));
|
||||
if (lu > UINT16_MAX || ld > UINT16_MAX) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, "member detail: socket link counts exceed wire limit id=%u up=%u down=%u", sid, lu, ld);
|
||||
if (lu > UINT16_MAX) lu = UINT16_MAX;
|
||||
if (ld > UINT16_MAX) ld = UINT16_MAX;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) *p++ = (uint8_t)(sid >> (8 * i));
|
||||
*p++ = (uint8_t)sp; *p++ = (uint8_t)(sp >> 8);
|
||||
*p++ = (uint8_t)lu; *p++ = (uint8_t)(lu >> 8);
|
||||
|
||||
Reference in new issue
Block a user