To: vim_dev@googlegroups.com Subject: Patch 8.0.0575 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0575 Problem: Using freed memory when resetting 'indentexpr' while evaluating it. (Dominique Pelle) Solution: Make a copy of 'indentexpr'. Files: src/misc1.c, src/testdir/test_options.vim *** ../vim-8.0.0574/src/misc1.c 2017-03-16 17:23:26.827815840 +0100 --- src/misc1.c 2017-04-20 22:54:31.964363642 +0200 *************** *** 9252,9257 **** --- 9252,9258 ---- get_expr_indent(void) { int indent; + char_u *inde_copy; pos_T save_pos; colnr_T save_curswant; int save_set_curswant; *************** *** 9268,9274 **** if (use_sandbox) ++sandbox; ++textlock; ! indent = (int)eval_to_number(curbuf->b_p_inde); if (use_sandbox) --sandbox; --textlock; --- 9269,9284 ---- if (use_sandbox) ++sandbox; ++textlock; ! ! /* Need to make a copy, the 'indentexpr' option could be changed while ! * evaluating it. */ ! inde_copy = vim_strsave(curbuf->b_p_inde); ! if (inde_copy != NULL) ! { ! indent = (int)eval_to_number(inde_copy); ! vim_free(inde_copy); ! } ! if (use_sandbox) --sandbox; --textlock; *** ../vim-8.0.0574/src/testdir/test_options.vim 2017-04-09 22:54:08.517238895 +0200 --- src/testdir/test_options.vim 2017-04-20 22:50:03.114139935 +0200 *************** *** 319,321 **** --- 319,334 ---- throw 'Skipped: opt_test.vim does not exist' endif endfunc + + func ResetIndentexpr() + set indentexpr= + endfunc + + func Test_set_indentexpr() + " this was causing usage of freed memory + set indentexpr=ResetIndentexpr() + new + call feedkeys("i\", 'x') + call assert_equal('', &indentexpr) + bwipe! + endfunc *** ../vim-8.0.0574/src/version.c 2017-04-20 22:44:42.600262225 +0200 --- src/version.c 2017-04-20 22:56:15.699679778 +0200 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 575, /**/ -- Courtroom Quote #19: Q: Doctor, how many autopsies have you performed on dead people? A: All my autopsies have been performed on dead people. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///