Skip to content

Commit 86fc2b0

Browse files
committed
shearwater: fix userdata corruption in predator parser samples loop
shearwater_predator_parser_samples_foreach serves two purposes: an internal calibration pre-pass called with callback=NULL and a dc_parser_sensor_calibration_t * as userdata, and normal sample enumeration called with a real callback and the caller's own userdata. The guard that restricted calibration writes to the pre-pass checked only that userdata was non-NULL, so during normal sample enumeration it cast the caller's userdata pointer to dc_parser_sensor_calibration_t * and wrote into it. For any CCR dive with internal (non-external) ppo2, this wrote the value 1 into the first byte of whatever struct the caller passed, e.g. the low byte of divecomputer::when in Subsurface (a small timestamp corruption) or a FILE * member in dctool (a crash). Fix: add !callback to the guard so the internal calibration writes only happen during the pre-pass (callback == NULL). Signed-off-by: Michael Keller <github@ike.ch>
1 parent c80c4b4 commit 86fc2b0

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/shearwater_predator_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
12241224
if ((status & PPO2_EXTERNAL) == 0) {
12251225
double calculated_ppo2 = data[offset + pnf + 6] / 100.0;
12261226

1227-
if (userdata) {
1227+
if (!callback && userdata) {
12281228
struct dc_parser_sensor_calibration_t *out = (struct dc_parser_sensor_calibration_t *)userdata;
12291229

12301230
out->external_ppo2_used = true;

0 commit comments

Comments
 (0)