From 76921ce29f0da4acbdae23202295491a86dcbbf6 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 10 Jun 2014 16:59:41 +1000 Subject: [PATCH] Fix end of message parsing logic fail --- src/ckpool.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 8a7fbd6f..9ce02a14 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -137,6 +137,7 @@ int read_socket_line(connsock_t *cs, int timeout) if (unlikely(cs->fd < 0)) goto out; + if (unlikely(!cs->buf)) cs->buf = ckzalloc(PAGESIZE); else if (cs->buflen) { @@ -144,9 +145,9 @@ int read_socket_line(connsock_t *cs, int timeout) memset(cs->buf + cs->buflen, 0, cs->bufofs); cs->bufofs = cs->buflen; cs->buflen = 0; + cs->buf[cs->bufofs] = '\0'; eom = strchr(cs->buf, '\n'); - } else - cs->bufofs = 0; + } while (42) { char readbuf[PAGESIZE] = {}; @@ -182,11 +183,11 @@ int read_socket_line(connsock_t *cs, int timeout) } ret = eom - cs->buf; - if (eom < cs->buf + cs->bufofs) { - cs->buflen = cs->buf + cs->bufofs - eom - 1; + cs->buflen = cs->buf + cs->bufofs - eom - 1; + if (cs->buflen) cs->bufofs = eom - cs->buf + 1; - } else - cs->buflen = cs->bufofs = 0; + else + cs->bufofs = 0; *eom = '\0'; out: if (ret < 0) {