From 306392950f15ea9d5cb4b5d60148e4589171d54b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 26 May 2014 18:31:32 +1000 Subject: [PATCH] Zero the read buffer fully in read_socket_line and handle closed sockets gracefully --- src/libckpool.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 4c13a1fe..58a67ff0 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -471,16 +471,19 @@ out: * memory in *buf */ int read_socket_line(connsock_t *cs, int timeout) { - char readbuf[PAGESIZE], *eom = NULL; size_t buflen = 0, bufofs = 0; + char *eom = NULL; tv_t tv_timeout; int ret, bufsiz; fd_set rd; dealloc(cs->buf); + if (unlikely(cs->fd < 0)) + return -1; + bufsiz = PAGESIZE; - readbuf[bufsiz - 1] = '\0'; while (!eom) { + char readbuf[PAGESIZE] = {}; int extralen; FD_ZERO(&rd);