aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-09-02 10:11:59 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-09-03 18:29:15 +0200
commitefef8773567753ca24e676c8744c8bfccda629ad (patch)
treeb88ee3835e2f49ab4f49c42ea89f7ce2569a2fec /src/buffer.c
parent254a0f7132b001e6800f53f9927136acd628ff0b (diff)
downloadlibssh-efef8773567753ca24e676c8744c8bfccda629ad.tar.gz
libssh-efef8773567753ca24e676c8744c8bfccda629ad.tar.xz
libssh-efef8773567753ca24e676c8744c8bfccda629ad.zip
buffer: Only reduce the buffer size if it gets bigger than 64K
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c12
1 files 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;
}
}