From 7401981c22a80a64af98609457ffe2786fe198ae Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 30 Sep 2016 10:43:14 +0800 Subject: [PATCH] realloc read buffer for control channel Signed-off-by: Gao feng --- src/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/init.c b/src/init.c index 67fe147..9b2a0a8 100644 --- a/src/init.c +++ b/src/init.c @@ -1200,8 +1200,15 @@ static int hyper_channel_read(struct hyper_event *he, int efd) // test it with '>=' to leave at least one byte in hyper_channel_handle(), // so that hyper_channel_handle() can convert the data to c-string inplace. if (len >= buf->size) { - fprintf(stderr, "get length %" PRIu32", too long\n", len); - return -1; + uint8_t *new_data; + fprintf(stderr, "get length %" PRIu32", too long, extend buffer\n", len); + new_data = realloc(buf->data, len + 1); + if (!new_data) { + perror("realloc channel read buffer failed"); + return -1; + } + buf->data = new_data; + buf->size = len + 1; } size = nonblock_read(he->fd, buf->data + buf->get, len - buf->get);