From dbffb29300f01dd6a4bfd219468d7f466b6caba3 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 10 Jun 2014 16:01:35 +1000 Subject: [PATCH] Append the null byte to the buffer before searching for the end of message marker --- src/ckpool.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index ce7c192a..f1c7fbd5 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -150,7 +150,6 @@ int read_socket_line(connsock_t *cs, int timeout) while (42) { char readbuf[PAGESIZE] = {}; - char *ptr; FD_ZERO(&rd); FD_SET(cs->fd, &rd); @@ -173,14 +172,13 @@ int read_socket_line(connsock_t *cs, int timeout) goto out; } buflen = cs->bufofs + ret + 1; - ptr = realloc(cs->buf, buflen); - if (unlikely(!ptr)) + cs->buf = realloc(cs->buf, buflen); + if (unlikely(!cs->buf)) quit(1, "Failed to alloc buf of %d bytes in read_socket_line", (int)buflen); - cs->buf = ptr; memcpy(cs->buf + cs->bufofs, readbuf, ret); - eom = strchr(cs->buf, '\n'); cs->bufofs += ret; cs->buf[cs->bufofs] = '\0'; + eom = strchr(cs->buf, '\n'); } ret = eom - cs->buf;