]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9766: Added 1 byte to ben_encode output and terminates output
authorShane Bryldt <astaelan@gmail.com>
Wed, 23 Nov 2016 19:49:48 +0000 (19:49 +0000)
committerShane Bryldt <astaelan@gmail.com>
Wed, 23 Nov 2016 19:49:48 +0000 (19:49 +0000)
libs/libks/src/ks_bencode.c

index e6f4abb3e1ba88b04787bf5fb5915ca6a7e138f7..2bf4cca7ff5f2b397ff12fd5825daf4420d08a84 100644 (file)
@@ -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;
 }