mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.4453: :helpgrep may free an option that was not allocated
Problem: :helpgrep may free an option that was not allocated. (Yegappan
Lakshmanan)
Solution: Check if the value was allocated.
4791fcd825
This commit is contained in:
parent
34c7007c32
commit
73bdfdd382
@ -3112,6 +3112,12 @@ void set_option_value_give_err(const char *name, long number, const char *string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_option_allocated(const char *name)
|
||||||
|
{
|
||||||
|
int idx = findoption(name);
|
||||||
|
return idx >= 0 && (options[idx].flags & P_ALLOCED);
|
||||||
|
}
|
||||||
|
|
||||||
/// Return true if "name" is a string option.
|
/// Return true if "name" is a string option.
|
||||||
/// Returns false if option "name" does not exist.
|
/// Returns false if option "name" does not exist.
|
||||||
bool is_string_option(const char *name)
|
bool is_string_option(const char *name)
|
||||||
|
@ -7065,6 +7065,7 @@ void ex_helpgrep(exarg_T *eap)
|
|||||||
bool updated = false;
|
bool updated = false;
|
||||||
// Make 'cpoptions' empty, the 'l' flag should not be used here.
|
// Make 'cpoptions' empty, the 'l' flag should not be used here.
|
||||||
char *const save_cpo = p_cpo;
|
char *const save_cpo = p_cpo;
|
||||||
|
const bool save_cpo_allocated = is_option_allocated("cpo");
|
||||||
p_cpo = empty_option;
|
p_cpo = empty_option;
|
||||||
|
|
||||||
bool new_qi = false;
|
bool new_qi = false;
|
||||||
@ -7104,8 +7105,10 @@ void ex_helpgrep(exarg_T *eap)
|
|||||||
if (*p_cpo == NUL) {
|
if (*p_cpo == NUL) {
|
||||||
set_option_value_give_err("cpo", 0L, save_cpo, 0);
|
set_option_value_give_err("cpo", 0L, save_cpo, 0);
|
||||||
}
|
}
|
||||||
|
if (save_cpo_allocated) {
|
||||||
free_string_option(save_cpo);
|
free_string_option(save_cpo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
// This may open a window and source scripts, do this after 'cpo' was
|
// This may open a window and source scripts, do this after 'cpo' was
|
||||||
|
@ -714,6 +714,33 @@ func Test_helpgrep()
|
|||||||
call s:test_xhelpgrep('l')
|
call s:test_xhelpgrep('l')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_helpgrep_restore_cpo_aucmd()
|
||||||
|
let save_cpo = &cpo
|
||||||
|
augroup QF_Test
|
||||||
|
au!
|
||||||
|
autocmd BufNew * set cpo=acd
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
helpgrep quickfix
|
||||||
|
call assert_equal('acd', &cpo)
|
||||||
|
%bw!
|
||||||
|
|
||||||
|
set cpo&vim
|
||||||
|
augroup QF_Test
|
||||||
|
au!
|
||||||
|
autocmd BufReadPost * set cpo=
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
helpgrep buffer
|
||||||
|
call assert_equal('', &cpo)
|
||||||
|
|
||||||
|
augroup QF_Test
|
||||||
|
au!
|
||||||
|
augroup END
|
||||||
|
%bw!
|
||||||
|
let &cpo = save_cpo
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_errortitle()
|
func Test_errortitle()
|
||||||
augroup QfBufWinEnter
|
augroup QfBufWinEnter
|
||||||
au!
|
au!
|
||||||
|
Loading…
Reference in New Issue
Block a user