Skip to content

Commit 4737b87

Browse files
committed
Fix unsigned underflow in buffer_check_append_limits()
Same pattern as buffer_check_limits() fix: when buf->used exceeds buf->writable_size, the unsigned subtraction wraps to a large value, bypassing the bounds check and taking the fast path without validation. Add used > writable_size guard before the subtraction.
1 parent 1e0583b commit 4737b87

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/lib/buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ buffer_check_append_limits(struct real_buffer *buf, size_t data_size)
129129
If it does, we don't even need to memset() the dirty buffer since
130130
it's going to be filled with the newly appended data. */
131131
#ifndef DEBUG_FAST
132-
if (buf->writable_size - buf->used < data_size)
132+
if (buf->used > buf->writable_size ||
133+
buf->writable_size - buf->used < data_size)
133134
buffer_check_limits(buf, buf->used, data_size);
134135
else
135136
buf->used += data_size;

0 commit comments

Comments
 (0)