skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 6a5f838c03ed16a335c6cb11e923aa95fa56217b
parent 2edb33dbe99c7b7e30904823da867f497a6acf65
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Sun, 14 Dec 2014 09:40:02 +0000

unixmessage_receive: don't read more than 1 message at a time

Diffstat:
Msrc/libunixonacid/unixmessage_receive.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 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 ;