From a58908df8e8a5cb21fd08cd495f0099d3f99b1f9 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 15 Oct 2018 15:37:50 +0200 Subject: Dive import: reset current_dive in process_imported_dives() process_imported_dives() might delete the currently selected dives. This could lead to use-after-free problems. Therefore, reset the currently selected dive to the last dive. Signed-off-by: Berthold Stoeger --- core/divelist.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/divelist.c') diff --git a/core/divelist.c b/core/divelist.c index 922c04e43..ec088a87e 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -1600,6 +1600,9 @@ void process_imported_dives(struct dive_table *import_table, bool prefer_importe if (!sequence_changed) try_to_renumber(preexisting); + /* We might have deleted the old selected dive. + * Choose the newest dive as selected (if any) */ + current_dive = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1] : NULL; mark_divelist_changed(true); } -- cgit v1.2.3-70-g09d2