From 3556560b383789469d638552d0bec5957c30c680 Mon Sep 17 00:00:00 2001 From: Petr Rockai Date: Mon, 16 Jan 2012 05:09:16 +0000 Subject: [PATCH] Fix a boundary condition in read_buffer in daemon-shared.c. --- daemons/common/daemon-shared.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/daemons/common/daemon-shared.c b/daemons/common/daemon-shared.c index 335b64be1..e4655596c 100644 --- a/daemons/common/daemon-shared.c +++ b/daemons/common/daemon-shared.c @@ -30,20 +30,19 @@ int read_buffer(int fd, char **buffer) { if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK) goto fail; + if ((!strncmp((*buffer) + bytes - 4, "\n##\n", 4))) { + *(*buffer + bytes - 4) = 0; + break; /* success, we have the full message now */ + } + if (bytes == buffersize) { buffersize += 1024; if (!(new = realloc(*buffer, buffersize + 1))) goto fail; *buffer = new; - } else { - (*buffer)[bytes] = 0; - if ((end = strstr((*buffer) + bytes - 4, "\n##\n"))) { - *end = 0; - break; /* success, we have the full message now */ - } - /* TODO call select here if we encountered EAGAIN/EWOULDBLOCK */ } + /* TODO call select here if we encountered EAGAIN/EWOULDBLOCK */ } return 1; fail: -- 2.43.5