From 6a5f838c03ed16a335c6cb11e923aa95fa56217b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sun, 14 Dec 2014 09:40:02 +0000 Subject: unixmessage_receive: don't read more than 1 message at a time --- src/libunixonacid/unixmessage_receive.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libunixonacid/unixmessage_receive.c b/src/libunixonacid/unixmessage_receive.c index bcba24b..a86ae10 100644 --- a/src/libunixonacid/unixmessage_receive.c +++ b/src/libunixonacid/unixmessage_receive.c @@ -92,8 +92,12 @@ int unixmessage_receive (unixmessage_receiver_t *b, unixmessage_t *m) for (;;) { register int r ; - b->maindata.len += cbuffer_get(&b->mainb, b->maindata.s + b->maindata.len, cbuffer_len(&b->mainb)) ; - b->auxdata.len += cbuffer_get(&b->auxb, b->auxdata.s + b->auxdata.len, cbuffer_len(&b->auxb)) ; + register unsigned int n = cbuffer_len(&b->mainb) ; + if (n > b->mainlen - b->maindata.len) n = b->mainlen - b->maindata.len ; + b->maindata.len += cbuffer_get(&b->mainb, b->maindata.s + b->maindata.len, n) ; + n = cbuffer_len(&b->auxb) ; + if (n > b->auxlen - b->auxdata.len) n = b->auxlen - b->auxdata.len ; + b->auxdata.len += cbuffer_get(&b->auxb, b->auxdata.s + b->auxdata.len, n) ; if (b->maindata.len == b->mainlen && b->auxdata.len == b->auxlen) break ; r = sanitize_read(unixmessage_receiver_fill(b)) ; if (r <= 0) return r ; -- cgit v1.2.3