From 2d1e0ae27545cd84a702b21c93e194e3c93e306e Mon Sep 17 00:00:00 2001 From: Shane Bryldt Date: Wed, 23 Nov 2016 19:49:48 +0000 Subject: [PATCH] FS-9766: Added 1 byte to ben_encode output and terminates output --- libs/libks/src/ks_bencode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/libks/src/ks_bencode.c b/libs/libks/src/ks_bencode.c index e6f4abb3e1..2bf4cca7ff 100644 --- a/libs/libks/src/ks_bencode.c +++ b/libs/libks/src/ks_bencode.c @@ -1667,7 +1667,7 @@ size_t ben_encoded_size(const struct bencode *b) void *ben_encode(size_t *len, const struct bencode *b) { size_t size = get_size(b); - void *data = malloc(size); + void *data = malloc(size + 1); struct ben_encode_ctx ctx = {.data = data, .size = size}; if (data == NULL) { //warn("No memory to encode\n"); @@ -1678,6 +1678,7 @@ void *ben_encode(size_t *len, const struct bencode *b) return NULL; } assert(ctx.pos == size); + ctx.data[size] = '\0'; *len = ctx.pos; return data; }