Skip to content

Commit

Permalink
Fix possible crashes due to view mode and tabs
Browse files Browse the repository at this point in the history
Use case 1
==========

e
q
:tabnew
e
q
:q
e

Use case 2
==========

e
<tab>
:tabnew
<space>
e
<tab>
:tabnew
:q
:q
  • Loading branch information
xaizek committed Nov 13, 2018
1 parent 58a6ca2 commit 20f1cf9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -5,6 +5,9 @@
Fixed access to uninitialized memory on clearing view after graphical
preview.

Fixed possible crashes after certain patterns of using view mode and
closing tabs.

0.10-beta to 0.10 (2018-11-11)

Display list of files in removal confirmation dialog. Thanks to ovk.
Expand Down
1 change: 1 addition & 0 deletions src/filelist.c
Expand Up @@ -310,6 +310,7 @@ flist_free_view(view_t *view)
update_string(&view->preview_prg_g, NULL);

view_info_free(view->vi);
view->vi = NULL;

regfree(&view->primary_group);
}
Expand Down
12 changes: 8 additions & 4 deletions src/modes/view.c
Expand Up @@ -1673,12 +1673,16 @@ view_info_alloc(void)
}

void
view_info_free(view_info_t *vi)
view_info_free(view_info_t *info)
{
if(vi != NULL)
if(info != NULL)
{
free_view_info(vi);
free(vi);
free_view_info(info);
free(info);
if(info == vi)
{
vi = NULL;
}
}
}

Expand Down
56 changes: 56 additions & 0 deletions tests/misc/commands_tabs.c
Expand Up @@ -7,12 +7,14 @@
#include "../../src/cfg/config.h"
#include "../../src/engine/keys.h"
#include "../../src/modes/modes.h"
#include "../../src/modes/view.h"
#include "../../src/modes/wk.h"
#include "../../src/ui/tabs.h"
#include "../../src/ui/ui.h"
#include "../../src/utils/fs.h"
#include "../../src/cmd_core.h"
#include "../../src/compare.h"
#include "../../src/filelist.h"

#include "utils.h"

Expand Down Expand Up @@ -325,5 +327,59 @@ TEST(tabs_are_moved)
}
}

TEST(view_mode_is_fine_with_tabs)
{
char cwd[PATH_MAX + 1];
assert_non_null(get_cwd(cwd, sizeof(cwd)));
make_abs_path(lwin.curr_dir, sizeof(lwin.curr_dir), TEST_DATA_PATH, "read",
cwd);
populate_dir_list(&lwin, 0);

(void)vle_keys_exec_timed_out(WK_e);
(void)vle_keys_exec_timed_out(WK_q);

assert_success(exec_commands("tabnew", &lwin, CIT_COMMAND));
assert_int_equal(2, tabs_count(&lwin));

(void)vle_keys_exec_timed_out(WK_e);
(void)vle_keys_exec_timed_out(WK_q);

assert_success(exec_commands("tabclose", &lwin, CIT_COMMAND));
assert_int_equal(1, tabs_count(&lwin));

(void)vle_keys_exec_timed_out(WK_e);
(void)vle_keys_exec_timed_out(WK_q);
}

TEST(left_view_mode_is_fine_with_tabs)
{
char cwd[PATH_MAX + 1];
assert_non_null(get_cwd(cwd, sizeof(cwd)));
make_abs_path(lwin.curr_dir, sizeof(lwin.curr_dir), TEST_DATA_PATH, "read",
cwd);
populate_dir_list(&lwin, 0);

(void)vle_keys_exec_timed_out(WK_e);
(void)vle_keys_exec_timed_out(WK_C_i);

assert_success(exec_commands("tabnew", &lwin, CIT_COMMAND));
assert_int_equal(2, tabs_count(&lwin));

(void)vle_keys_exec_timed_out(WK_SPACE);
(void)vle_keys_exec_timed_out(WK_e);
(void)vle_keys_exec_timed_out(WK_C_i);

assert_success(exec_commands("tabnew", &lwin, CIT_COMMAND));
assert_int_equal(3, tabs_count(&lwin));

assert_success(exec_commands("q", &lwin, CIT_COMMAND));
assert_int_equal(2, tabs_count(&lwin));
assert_success(exec_commands("q", &lwin, CIT_COMMAND));
assert_int_equal(1, tabs_count(&lwin));

(void)vle_keys_exec_timed_out(WK_SPACE);
(void)vle_keys_exec_timed_out(WK_q);
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 : */

0 comments on commit 20f1cf9

Please sign in to comment.