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:
parent
f5f855d428
commit
e0cf41a14e
@ -78,6 +78,18 @@ dc_rbstream_new (dc_rbstream_t **out, dc_device_t *device, unsigned int pagesize
|
|||||||
return DC_STATUS_INVALIDARGS;
|
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.
|
// Address should be inside the ringbuffer.
|
||||||
if (address < begin || address > end) {
|
if (address < begin || address > end) {
|
||||||
ERROR (device->context, "Address outside the ringbuffer!");
|
ERROR (device->context, "Address outside the ringbuffer!");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user