From 5140d2b3070f211e6d8a0ad7cb0a190e8b6f3e28 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 23 May 2014 09:26:11 -0400 Subject: [PATCH] Fix: refuse overwrite mode buffers with less than two subbuffers Fixes #793 Signed-off-by: Mathieu Desnoyers --- lib/ringbuffer/ring_buffer_backend.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ringbuffer/ring_buffer_backend.c b/lib/ringbuffer/ring_buffer_backend.c index f7ed20df..3cc22d77 100644 --- a/lib/ringbuffer/ring_buffer_backend.c +++ b/lib/ringbuffer/ring_buffer_backend.c @@ -331,6 +331,12 @@ int channel_backend_init(struct channel_backend *chanb, return -EINVAL; if (!num_subbuf || (num_subbuf & (num_subbuf - 1))) return -EINVAL; + /* + * Overwrite mode buffers require at least 2 subbuffers per + * buffer. + */ + if (config->mode == RING_BUFFER_OVERWRITE && num_subbuf < 2) + return -EINVAL; ret = subbuffer_id_check_index(config, num_subbuf); if (ret) -- 2.39.5