From 0756386c482be894d74b68586317aaae66fd1d9c Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Mon, 28 Mar 2016 00:17:19 +0300 Subject: [PATCH] [core] fixed bug with endless loop on master accept; --- include/sxmp/limits.h | 2 ++ lib/sxmplv2.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/sxmp/limits.h b/include/sxmp/limits.h index 79f7cba..4697621 100644 --- a/include/sxmp/limits.h +++ b/include/sxmp/limits.h @@ -41,4 +41,6 @@ #define MAX_LINKS 32768 +#define MAX_SXMP_SYNC_ITERATIONS 6 + #endif /* __SXMP_LIMITS_H__ */ diff --git a/lib/sxmplv2.c b/lib/sxmplv2.c index 8fb340d..df4e9b8 100644 --- a/lib/sxmplv2.c +++ b/lib/sxmplv2.c @@ -986,6 +986,7 @@ sxlink_t *sxlink_master_accept(sxhub_t *hub, int sck, struct in_addr *addr) } bbuf = (char *)buf; bbuf += sizeof(sxmplv2_head_t); + i = 0; while(link->flags & SXMP_BATCHMODE) { rd = __conn_read(link, buf, sizeof(sxmplv2_head_t)); @@ -995,11 +996,18 @@ sxlink_t *sxlink_master_accept(sxhub_t *hub, int sck, struct in_addr *addr) /* check for returns */ if(head->opcode != SXE_SUCCESS) { r = head->opcode; goto __fail3; } else { /* opcode is fine */ + i++; /* if we're ready for messaging mode, turn off batch mode */ if(link->flags & SXMP_MESSAGINGMODE) { link->flags &= ~SXMP_BATCHMODE; break; } + + /* if count too big - fail */ + if(i > MAX_SXMP_SYNC_ITERATIONS) { /* ugly */ + r = SXE_FAILED; + goto __fail3; + } } if(!head->payload_length) continue; /* pass the following check up */