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 2018-02-20 20:49:17 +01:00
parent 38c3f289b5
commit 5344f3926a

View File

@ -170,8 +170,8 @@ receive_packet(suunto_eonsteel_device_t *eon, unsigned char *buffer, unsigned in
return DC_STATUS_PROTOCOL;
}
if (len > size) {
ERROR(eon->base.context, "receive_packet result buffer too small - truncating");
len = size;
ERROR(eon->base.context, "receive_packet result buffer too small");
return DC_STATUS_PROTOCOL;
}
HEXDUMP (eon->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf+2, len);
memcpy(buffer, buf+2, len);
@ -354,8 +354,8 @@ send_receive(suunto_eonsteel_device_t *eon,
return DC_STATUS_PROTOCOL;
}
if (actual > len_in) {
ERROR(eon->base.context, "command reply too big for result buffer - truncating");
actual = len_in;
ERROR(eon->base.context, "command reply too big for result buffer");
return DC_STATUS_PROTOCOL;
}
/* Get the rest of the data */