visomat-data-downloader: more precise data validation in decode_eeprom()
authorAntonio Ospite <ao2@ao2.it>
Sat, 9 Jan 2016 18:12:38 +0000 (19:12 +0100)
committerAntonio Ospite <ao2@ao2.it>
Sat, 9 Jan 2016 18:12:38 +0000 (19:12 +0100)
src/visomat-data-downloader.c

index 1b4cde9..a53f72c 100644 (file)
@@ -133,8 +133,15 @@ static int decode_eeprom(uint8_t *buffer,
        struct datetime d;
        struct pressure p;
 
        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;
                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;
 
        /* skip the initial STX */
        i = 1;