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:
Jef Driesen 2017-06-20 21:25:36 +02:00
parent eae071c97d
commit 06259fed19

View File

@ -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);
if (len > size) {
ERROR (device->base.context, "receive result buffer too small - truncating");
len = size;
ERROR (device->base.context, "receive result buffer too small");
return DC_STATUS_PROTOCOL;
}
memcpy(data, buf + 1, len);
size -= len;