From 8a10e545d4b77a2a892fafeb0de7d34df8a5cd63 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 18 Sep 2020 17:29:52 +0200 Subject: [PATCH 1/3] Fix a bug in the salt and fresh water parsing The original Mares Genius support was based on Mares Dive Organizer 2.25, which has a bug in the salinity parsing. The latest version 2.26 has this bug fixed. Reported-by: Greg McLaughlin --- src/mares_iconhd_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index a76ca20..5d35bea 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -76,8 +76,8 @@ #define GASMIX_INUSE 2 #define GASMIX_IGNRD 3 -#define WATER_SALT 0 -#define WATER_FRESH 1 +#define WATER_FRESH 0 +#define WATER_SALT 1 #define WATER_EN13319 2 #define ALARM_NONE 0 From 469d3ee17728d0e4c31bc0205d2cd13245d7f9f0 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 19 Sep 2020 10:29:55 -0700 Subject: [PATCH 2/3] fix Shearwater PNF parsing for Petrel / Petrel 2 At some point (possibly around v71 of their firmware), Shearwater implemented PNF for the Petrel and Petrel 2. Those are of course not air integrated, and apparently don't support adjustable sample rate, so the log data doesn't include opening and closing record 5. Instead of failing when those aren't found, we should simply only access those when they actually exist. Signed-off-by: Dirk Hohndel --- src/shearwater_predator_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 7ccbc97..43eefa8 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -468,7 +468,10 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) } // Verify the required opening/closing records. - for (unsigned int i = 0; i < NRECORDS - 2; ++i) { + // At least in firmware v71 and newer, Petrel and Petrel 2 also use PNF, + // and there opening/closing record 5 (which contains AI information plus + // the sample interval) don't appear to exist - so don't mark them as required + for (unsigned int i = 0; i <= 4; ++i) { if (parser->opening[i] == UNDEFINED || parser->closing[i] == UNDEFINED) { ERROR (abstract->context, "Opening or closing record %u not found.", i); return DC_STATUS_DATAFORMAT; @@ -627,7 +630,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Sample interval. unsigned int time = 0; unsigned int interval = 10; - if (parser->pnf && parser->logversion >= 9) { + if (parser->pnf && parser->logversion >= 9 && parser->opening[5] != UNDEFINED) { interval = array_uint16_be (data + parser->opening[5] + 23); if (interval % 1000 != 0) { ERROR (abstract->context, "Unsupported sample interval (%u ms).", interval); From c6ea7afb7656ea40265639029fca0ff177ea8414 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 21 Sep 2020 10:29:55 +0200 Subject: [PATCH 3/3] Fix a buffer overflow The existing check accepts the number of array elements as a valid index. That's clearly wrong for zero based indexing, and would result in a buffer overflow. --- src/liquivision_lynx_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liquivision_lynx_parser.c b/src/liquivision_lynx_parser.c index 8489a50..ca41e21 100644 --- a/src/liquivision_lynx_parser.c +++ b/src/liquivision_lynx_parser.c @@ -333,7 +333,7 @@ liquivision_lynx_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Get the sample interval. unsigned int interval_idx = data[39]; const unsigned int intervals[] = {1, 2, 5, 10, 30, 60}; - if (interval_idx > C_ARRAY_SIZE(intervals)) { + if (interval_idx >= C_ARRAY_SIZE(intervals)) { ERROR (abstract->context, "Invalid sample interval index %u", interval_idx); return DC_STATUS_DATAFORMAT; }