Fix: space left in buffer may be uninitilized on capacity increase
[lttng-tools.git] / src / common / dynamic-buffer.c
index 7184a3400888ce602c9ec59377ee9c426fc3a5ee..c295a5d2eb378f58b557fdfa6c841de6667db810 100644 (file)
@@ -101,10 +101,22 @@ int lttng_dynamic_buffer_set_size(struct lttng_dynamic_buffer *buffer,
        }
 
        if (new_size > buffer->capacity) {
+               size_t original_size = buffer->size;
+               size_t original_capacity = buffer->capacity;
+
                ret = lttng_dynamic_buffer_set_capacity(buffer, new_size);
                if (ret) {
                        goto end;
                }
+
+               /*
+                * Zero-initialize the space that was left in the buffer at the
+                * before we increased its capacity (original capacity - original size).
+                * The newly acquired capacity (new capacity - original capacity)
+                * is zeroed by lttng_dynamic_buffer_set_capacity().
+                */
+               memset(buffer->data + original_size, 0,
+                               original_capacity - original_size);
        } else if (new_size > buffer->size) {
                memset(buffer->data + buffer->size, 0, new_size - buffer->size);
        } else {
This page took 0.032874 seconds and 4 git commands to generate.