From 2893bc652055b00eb963f942d2556f9c195a8a70 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 16 Oct 2018 17:35:54 -0700 Subject: [PATCH] Ensure a resized empty buffer is null-terminated The new buffer code is using the pool, which ensures its buffers are null-terminated. However, if a "new" buffer from another part of the code were passed to one of the temporary interfaces that resizes the buffer, it's possible a non-terminated string might end up being passed through. It's reasonable to expect mutt_b2s() for a "new" buffer should be the same as after it is resized larger. So ensure the resulting buf->data is properly terminated to avoid surprises. --- mutt/buffer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mutt/buffer.c b/mutt/buffer.c index 3278c4868..3c1196f1f 100644 --- a/mutt/buffer.c +++ b/mutt/buffer.c @@ -336,6 +336,8 @@ void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size) buf->dsize = new_size; mutt_mem_realloc(&buf->data, buf->dsize); buf->dptr = buf->data + offset; + /* This ensures an initially NULL buf->data is now properly terminated. */ + *buf->dptr = '\0'; } /** -- 2.40.0