diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-05-04 21:49:48 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-05-05 19:43:13 +0800 |
commit | 17c8e39f8803daa6f0e6106ce1c087240cef4771 (patch) | |
tree | b55ced02f17abbee930fc4c2e062a40be1639b94 /src/nvim/testing.c | |
parent | 0a3a2132d43be3a376214f75157d4d2b1340311e (diff) | |
download | rneovim-17c8e39f8803daa6f0e6106ce1c087240cef4771.tar.gz rneovim-17c8e39f8803daa6f0e6106ce1c087240cef4771.tar.bz2 rneovim-17c8e39f8803daa6f0e6106ce1c087240cef4771.zip |
vim-patch:9.0.0213: using freed memory with error in assert argument
Problem: Using freed memory with error in assert argument.
Solution: Make a copy of the error.
https://github.com/vim/vim/commit/249e1b903a9c0460d618f6dcc59aeb8c03b24b20
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/testing.c')
-rw-r--r-- | src/nvim/testing.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 27d5334fc5..25149f1b38 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -510,6 +510,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const int save_trylevel = trylevel; const int called_emsg_before = called_emsg; const char *wrong_arg_msg = NULL; + char *tofree = NULL; if (tv_check_for_string_or_number_arg(argvars, 0) == FAIL || tv_check_for_opt_string_or_list_arg(argvars, 1) == FAIL @@ -560,8 +561,9 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) error_found = true; expected_str = expected; } else if (tv_list_len(list) == 2) { + // make a copy, an error in pattern_match() may free it + tofree = actual = xstrdup(get_vim_var_str(VV_ERRMSG)); tv = TV_LIST_ITEM_TV(tv_list_last(list)); - actual = get_vim_var_str(VV_ERRMSG); expected = tv_get_string_buf_chk(tv, buf); if (!pattern_match(expected, actual, false)) { error_found = true; @@ -632,6 +634,7 @@ theend: msg_reset_scroll(); lines_left = Rows; XFREE_CLEAR(emsg_assert_fails_msg); + xfree(tofree); set_vim_var_string(VV_ERRMSG, NULL, 0); if (wrong_arg_msg != NULL) { emsg(_(wrong_arg_msg)); |