Abort with an error if the buffer is too small
Silently truncating the data packet if the buffer is too small will result in a corrupt data stream.
This commit is contained in:
parent
eae071c97d
commit
06259fed19
@ -85,8 +85,8 @@ receive_data (uwatec_g2_device_t *device, unsigned char *data, unsigned int size
|
|||||||
}
|
}
|
||||||
HEXDUMP (device->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf + 1, len);
|
HEXDUMP (device->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf + 1, len);
|
||||||
if (len > size) {
|
if (len > size) {
|
||||||
ERROR (device->base.context, "receive result buffer too small - truncating");
|
ERROR (device->base.context, "receive result buffer too small");
|
||||||
len = size;
|
return DC_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
memcpy(data, buf + 1, len);
|
memcpy(data, buf + 1, len);
|
||||||
size -= len;
|
size -= len;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user