From 80b808dbfeb14968561b6bbd2abdc77b522f262c Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 28 Nov 2016 19:30:38 -0500 Subject: rbuffer: Use xcalloc to ensure memory is initialized Since the rbuffer contents are used by string functions (like sscan, strlen, etc.), it is not safe to use uninitialized memory. Using xcalloc ensures the string-based functions do not run past the end of the buffer. Closes #5676 --- src/nvim/rbuffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c index a2cc432eca..111af0d0fb 100644 --- a/src/nvim/rbuffer.c +++ b/src/nvim/rbuffer.c @@ -18,7 +18,7 @@ RBuffer *rbuffer_new(size_t capacity) capacity = 0x10000; } - RBuffer *rv = xmalloc(sizeof(RBuffer) + capacity); + RBuffer *rv = xcalloc(1, sizeof(RBuffer) + capacity); rv->full_cb = rv->nonfull_cb = NULL; rv->data = NULL; rv->size = 0; @@ -78,7 +78,7 @@ void rbuffer_reset(RBuffer *buf) FUNC_ATTR_NONNULL_ALL size_t temp_size; if ((temp_size = rbuffer_size(buf))) { if (buf->temp == NULL) { - buf->temp = xmalloc(rbuffer_capacity(buf)); + buf->temp = xcalloc(1, rbuffer_capacity(buf)); } rbuffer_read(buf, buf->temp, buf->size); } -- cgit