mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: sanitize pressure-sensor cylinder ids in fixup_dive()
The code will happily perform out-of-bound accesses if pressure-sensors refer to non-existing cylinders. Therefore, sanitize these values in fixup_dive(), which is called everytime a dive is loaded or imported. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
361678dcbe
commit
82f967ddb3
1 changed files with 14 additions and 0 deletions
14
core/dive.c
14
core/dive.c
|
@ -1208,6 +1208,17 @@ static void fixup_no_o2sensors(struct divecomputer *dc)
|
|||
}
|
||||
}
|
||||
|
||||
static void fixup_dc_sample_sensors(struct divecomputer *dc, int nr_cylinders)
|
||||
{
|
||||
for (int i = 0; i < dc->samples; i++) {
|
||||
struct sample *s = dc->sample + i;
|
||||
for (int j = 0; j < MAX_SENSORS; j++) {
|
||||
if (s->sensor[j] < 0 || s->sensor[j] >= nr_cylinders)
|
||||
s->sensor[j] = NO_SENSOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
|
||||
{
|
||||
/* Fixup duration and mean depth */
|
||||
|
@ -1228,6 +1239,9 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
|
|||
/* Fix up cylinder pressures based on DC info */
|
||||
fixup_dive_pressures(dive, dc);
|
||||
|
||||
/* Fix up cylinder ids in pressure sensors */
|
||||
fixup_dc_sample_sensors(dc, dive->cylinders.nr);
|
||||
|
||||
fixup_dc_events(dc);
|
||||
|
||||
/* Fixup CCR / PSCR dives with o2sensor values, but without no_o2sensors */
|
||||
|
|
Loading…
Add table
Reference in a new issue