From e0cf41a14e730a3c83e9c0d4ff548b029f7e55f8 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 11 Dec 2023 21:02:03 +0100 Subject: [PATCH] Add some extra parameter validation The ringbuffer boundary addresses (begin/end) should be ordered correctly, and the packet size should be smaller than the ringbuffer size, otherwise the code won't work as expected. --- src/rbstream.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rbstream.c b/src/rbstream.c index 07188e0..e16f872 100644 --- a/src/rbstream.c +++ b/src/rbstream.c @@ -78,6 +78,18 @@ dc_rbstream_new (dc_rbstream_t **out, dc_device_t *device, unsigned int pagesize return DC_STATUS_INVALIDARGS; } + // Ringbuffer boundaries should not be reversed. + if (begin > end) { + ERROR (device->context, "Ringbuffer boundaries reversed!"); + return DC_STATUS_INVALIDARGS; + } + + // Packet size should be smaller than the ringbuffer size. + if (packetsize > (end - begin)) { + ERROR (device->context, "Packet size larger than the ringbuffer size!"); + return DC_STATUS_INVALIDARGS; + } + // Address should be inside the ringbuffer. if (address < begin || address > end) { ERROR (device->context, "Address outside the ringbuffer!");