From efef8773567753ca24e676c8744c8bfccda629ad Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 2 Sep 2018 10:11:59 +0200 Subject: [PATCH] buffer: Only reduce the buffer size if it gets bigger than 64K Signed-off-by: Andreas Schneider --- src/buffer.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 54c17ded..9e7d267e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -249,6 +249,9 @@ static void buffer_shift(ssh_buffer buffer) /** * @brief Reinitialize a SSH buffer. * + * In case the buffer has exceeded 64K in size, the buffer will be reallocated + * to 64K. + * * @param[in] buffer The buffer to reinitialize. * * @return 0 on success, < 0 on error. @@ -267,8 +270,13 @@ int ssh_buffer_reinit(struct ssh_buffer_struct *buffer) buffer->used = 0; buffer->pos = 0; - if (buffer->allocated > 127) { - if (realloc_buffer(buffer, 127) < 0) { + /* If the buffer is bigger then 64K, reset it to 64K */ + if (buffer->allocated > 65536) { + int rc; + + /* -1 for realloc_buffer magic */ + rc = realloc_buffer(buffer, 65536 - 1); + if (rc != 0) { return -1; } }