From a99d990117c8806cb566b6a602317cd5976900ae Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 27 Oct 2022 20:14:29 +0200 Subject: [PATCH] Verify the fields of the compact header When downloading the compact headers (which is the default for recent hwOS firmware), it's not possible to compare the entire dive header, but we can at least the check the fields that are available. Also return an error if the verification fails. --- src/hw_ostc3.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 2b4c262..cfb25d7 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -92,10 +92,12 @@ #define HDR_COMPACT_LENGTH 0 // 3 bytes #define HDR_COMPACT_SUMMARY 3 // 10 bytes #define HDR_COMPACT_NUMBER 13 // 2 bytes +#define HDR_COMPACT_VERSION 15 // 1 byte #define HDR_FULL_LENGTH 9 // 3 bytes #define HDR_FULL_SUMMARY 12 // 10 bytes #define HDR_FULL_NUMBER 80 // 2 bytes +#define HDR_FULL_VERSION 8 // 1 byte #define HDR_FULL_FIRMWARE 48 // 2 bytes @@ -844,11 +846,16 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi } // Verify the header in the logbook and profile are identical. - if (!compact && memcmp (profile, header + offset, logbook->size) != 0) { + if (compact ? + memcmp (profile + HDR_FULL_LENGTH, header + offset + HDR_COMPACT_LENGTH, 3) != 0 || + memcmp (profile + HDR_FULL_SUMMARY, header + offset + HDR_COMPACT_SUMMARY, 10) != 0 || + memcmp (profile + HDR_FULL_NUMBER, header + offset + HDR_COMPACT_NUMBER, 2) != 0 || + memcmp (profile + HDR_FULL_VERSION, header + offset + HDR_COMPACT_VERSION, 1) != 0 : + memcmp (profile, header + offset, RB_LOGBOOK_SIZE_FULL) != 0) { ERROR (abstract->context, "Unexpected profile header."); free (profile); free (header); - return rc; + return DC_STATUS_DATAFORMAT; } // Detect invalid profile data.