Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ buffer_check_limits(struct real_buffer *buf, size_t pos, size_t data_size)
{
size_t new_size;

if (unlikely(buf->max_size - pos < data_size))
if (unlikely(pos > buf->max_size || buf->max_size - pos < data_size))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good fix, although commit message could say that this doesn't affect buffers created with buffer_create_dynamic(), which are most buffers, since then max_size == SIZE_MAX. Also commit title needs a lib: prefix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added lib: prefix and noted the buffer_create_dynamic() / SIZE_MAX scope in the commit message.

i_panic("Buffer write out of range (%zu + %zu)", pos, data_size);

new_size = pos + data_size;
Expand Down Expand Up @@ -129,6 +129,7 @@ buffer_check_append_limits(struct real_buffer *buf, size_t data_size)
If it does, we don't even need to memset() the dirty buffer since
it's going to be filled with the newly appended data. */
#ifndef DEBUG_FAST
i_assert(buf->used <= buf->writable_size);
if (buf->writable_size - buf->used < data_size)
buffer_check_limits(buf, buf->used, data_size);
else
Expand Down