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.
This commit is contained in:
Jef Driesen 2023-12-11 21:02:03 +01:00
parent f5f855d428
commit e0cf41a14e

View File

@ -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!");