From 5344f3926a85c5c39b38665fe808ac94231745d9 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 20 Feb 2018 20:49:17 +0100 Subject: [PATCH] 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. --- src/suunto_eonsteel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 14358c3..719ca64 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -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 */