summaryrefslogtreecommitdiffstats
path: root/PICA_node.c
diff options
context:
space:
mode:
authorAnton <anton@picapica.im>2026-11-11 05:48:09 +0400
committerAnton <anton@picapica.im>2026-11-11 05:48:09 +0400
commitd7a200a36b9c2baf1e328823b3e522b5c2fa2d90 (patch)
treed3cda8f22ed99df45801ec4330f960f1261e067e /PICA_node.c
parent16d89ac0bf64122453b3730fafa46d54e278480d (diff)
downloadpica-pica-d7a200a36b9c2baf1e328823b3e522b5c2fa2d90.tar.gz
pica-pica-d7a200a36b9c2baf1e328823b3e522b5c2fa2d90.zip
pica-node: fix N2N messages processing
Diffstat (limited to 'PICA_node.c')
-rw-r--r--PICA_node.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/PICA_node.c b/PICA_node.c
index ec93776..47b23e0 100644
--- a/PICA_node.c
+++ b/PICA_node.c
@@ -1160,7 +1160,13 @@ unsigned int procmsg_N2NALLOW(unsigned char* buf, unsigned int size, void* ptr)
cc = cclink_list_search(caller_id, callee_id);
- if (cc)
+ /* N2NALLOW is the reply this (caller's) node awaits in N2NCLR_WAITREP.
+ * That state only exists on caller-local links, which always have a
+ * non-NULL p1 - gating on it both prevents a client_wbuf_push(NULL) on a
+ * callee-local (p1 == NULL) link an attacker can create with
+ * N2NCONNREQOUTG, and stops a stray N2NALLOW from disturbing other links.
+ */
+ if (cc && cc->state == PICA_CCLINK_N2NCLR_WAITREP)
{
if ((mp = client_wbuf_push(cc->p1, PICA_PROTO_FOUND, PICA_PROTO_FOUND_SIZE)))
{
@@ -1185,7 +1191,11 @@ unsigned int procmsg_N2NNOTFOUND(unsigned char* buf, unsigned int size, void* pt
cc = cclink_list_search(caller_id, callee_id);
- if (cc)
+ /* Same gate as N2NALLOW: act only on the caller-local link awaiting this
+ * reply, so a callee-local link (p1 == NULL) cannot crash client_wbuf_push
+ * and a stray N2NNOTFOUND cannot delete an unrelated link.
+ */
+ if (cc && cc->state == PICA_CCLINK_N2NCLR_WAITREP)
{
if ((mp = client_wbuf_push(cc->p1, PICA_PROTO_NOTFOUND, PICA_PROTO_NOTFOUND_SIZE)))
{