From: Antonio Ospite Date: Sat, 9 Jan 2016 18:12:38 +0000 (+0100) Subject: visomat-data-downloader: more precise data validation in decode_eeprom() X-Git-Url: https://git.ao2.it/visomat-utils.git/commitdiff_plain/f91f4b7f1117037fffa21cfb0a6b43aa9036c994 visomat-data-downloader: more precise data validation in decode_eeprom() --- diff --git a/src/visomat-data-downloader.c b/src/visomat-data-downloader.c index 1b4cde9..a53f72c 100644 --- a/src/visomat-data-downloader.c +++ b/src/visomat-data-downloader.c @@ -133,8 +133,15 @@ static int decode_eeprom(uint8_t *buffer, struct datetime d; struct pressure p; - if (buffer[0] != STX || buffer[1] != 'M' || buffer[len - 1] != ETX) + if (buffer[0] != STX || buffer[1] != 'M') { + fprintf(stderr, "Usupported data.\n"); return -EINVAL; + } + + if (buffer[len - 1] != ETX) { + fprintf(stderr, "Bad terminator in data. Buffer too small?\n"); + return -EINVAL; + } /* skip the initial STX */ i = 1;