mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.4924: maparg() may return a string that cannot be reused
Problem: maparg() may return a string that cannot be reused. Solution: use msg_outtrans_special() instead of str2special(). (closes #10384)
This commit is contained in:
parent
194843028e
commit
0519ce0039
@ -1721,6 +1721,9 @@ msg_outtrans_special(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
text = (char *)str2special(&str, from);
|
text = (char *)str2special(&str, from);
|
||||||
|
if (text[0] != NUL && text[1] == NUL)
|
||||||
|
// single-byte character or illegal byte
|
||||||
|
text = (char *)transchar_byte((char_u)text[0]);
|
||||||
len = vim_strsize((char_u *)text);
|
len = vim_strsize((char_u *)text);
|
||||||
if (maxlen > 0 && retval + len >= maxlen)
|
if (maxlen > 0 && retval + len >= maxlen)
|
||||||
break;
|
break;
|
||||||
@ -1755,6 +1758,7 @@ str2special_save(
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the printable string for the key codes at "*sp".
|
* Return the printable string for the key codes at "*sp".
|
||||||
|
* On illegal byte return a string with only that byte.
|
||||||
* Used for translating the lhs or rhs of a mapping to printable chars.
|
* Used for translating the lhs or rhs of a mapping to printable chars.
|
||||||
* Advances "sp" to the next code.
|
* Advances "sp" to the next code.
|
||||||
*/
|
*/
|
||||||
@ -1798,38 +1802,28 @@ str2special(
|
|||||||
special = TRUE;
|
special = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_mbyte && !IS_SPECIAL(c))
|
if (has_mbyte && !IS_SPECIAL(c) && MB_BYTE2LEN(c) > 1)
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
*sp = str;
|
*sp = str;
|
||||||
// Try to un-escape a multi-byte character after modifiers.
|
// Try to un-escape a multi-byte character after modifiers.
|
||||||
p = mb_unescape(sp);
|
p = mb_unescape(sp);
|
||||||
|
if (p != NULL)
|
||||||
if (p == NULL)
|
// Since 'special' is TRUE the multi-byte character 'c' will be
|
||||||
{
|
// processed by get_special_key_name()
|
||||||
int len = (*mb_ptr2len)(str);
|
c = (*mb_ptr2char)(p);
|
||||||
|
else
|
||||||
// Check for an illegal byte.
|
// illegal byte
|
||||||
if (MB_BYTE2LEN(*str) > len)
|
*sp = str + 1;
|
||||||
{
|
|
||||||
transchar_nonprint(curbuf, buf, c);
|
|
||||||
*sp = str + 1;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
*sp = str + len;
|
|
||||||
p = str;
|
|
||||||
}
|
|
||||||
// Since 'special' is TRUE the multi-byte character 'c' will be
|
|
||||||
// processed by get_special_key_name()
|
|
||||||
c = (*mb_ptr2char)(p);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
// single-byte character or illegal byte
|
||||||
*sp = str + 1;
|
*sp = str + 1;
|
||||||
|
|
||||||
// Make unprintable characters in <> form, also <M-Space> and <Tab>.
|
// Make special keys and C0 control characters in <> form, also <M-Space>.
|
||||||
// Use <Space> only for lhs of a mapping.
|
// Use <Space> only for lhs of a mapping.
|
||||||
if (special || char2cells(c) > 1 || (from && c == ' '))
|
if (special || c < ' ' || (from && c == ' '))
|
||||||
return get_special_key_name(c, modifiers);
|
return get_special_key_name(c, modifiers);
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
buf[1] = NUL;
|
buf[1] = NUL;
|
||||||
|
@ -4017,6 +4017,8 @@ get_option_value(
|
|||||||
if ((char_u **)varp == &curbuf->b_p_key
|
if ((char_u **)varp == &curbuf->b_p_key
|
||||||
&& **(char_u **)(varp) != NUL)
|
&& **(char_u **)(varp) != NUL)
|
||||||
*stringval = vim_strsave((char_u *)"*****");
|
*stringval = vim_strsave((char_u *)"*****");
|
||||||
|
else if ((char_u **)varp == &p_pt) // 'pastetoggle'
|
||||||
|
*stringval = str2special_save(*(char_u **)(varp), FALSE);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
*stringval = vim_strsave(*(char_u **)(varp));
|
*stringval = vim_strsave(*(char_u **)(varp));
|
||||||
|
@ -58,6 +58,20 @@ func Test_maparg()
|
|||||||
map abc y<S-char-114>y
|
map abc y<S-char-114>y
|
||||||
call assert_equal("yRy", maparg('abc'))
|
call assert_equal("yRy", maparg('abc'))
|
||||||
|
|
||||||
|
" character with K_SPECIAL byte
|
||||||
|
nmap abc …
|
||||||
|
call assert_equal('…', maparg('abc'))
|
||||||
|
|
||||||
|
" modified character with K_SPECIAL byte
|
||||||
|
nmap abc <M-…>
|
||||||
|
call assert_equal('<M-…>', maparg('abc'))
|
||||||
|
|
||||||
|
" illegal bytes
|
||||||
|
let str = ":\x7f:\x80:\x90:\xd0:"
|
||||||
|
exe 'nmap abc ' .. str
|
||||||
|
call assert_equal(str, maparg('abc'))
|
||||||
|
unlet str
|
||||||
|
|
||||||
omap { w
|
omap { w
|
||||||
let d = maparg('{', 'o', 0, 1)
|
let d = maparg('{', 'o', 0, 1)
|
||||||
call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode])
|
call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode])
|
||||||
|
@ -502,6 +502,13 @@ func Test_list_mappings()
|
|||||||
call assert_equal(['n <M-…> foo'],
|
call assert_equal(['n <M-…> foo'],
|
||||||
\ execute('nmap <M-…>')->trim()->split("\n"))
|
\ execute('nmap <M-…>')->trim()->split("\n"))
|
||||||
|
|
||||||
|
" illegal bytes
|
||||||
|
let str = ":\x7f:\x80:\x90:\xd0:"
|
||||||
|
exe 'nmap foo ' .. str
|
||||||
|
call assert_equal(['n foo ' .. strtrans(str)],
|
||||||
|
\ execute('nmap foo')->trim()->split("\n"))
|
||||||
|
unlet str
|
||||||
|
|
||||||
" map to CTRL-V
|
" map to CTRL-V
|
||||||
exe "nmap ,k \<C-V>"
|
exe "nmap ,k \<C-V>"
|
||||||
call assert_equal(['n ,k <Nop>'],
|
call assert_equal(['n ,k <Nop>'],
|
||||||
|
@ -48,6 +48,26 @@ func Test_isfname()
|
|||||||
set isfname&
|
set isfname&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for getting the value of 'pastetoggle'
|
||||||
|
func Test_pastetoggle()
|
||||||
|
" character with K_SPECIAL byte
|
||||||
|
let &pastetoggle = '…'
|
||||||
|
call assert_equal('…', &pastetoggle)
|
||||||
|
call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
|
||||||
|
|
||||||
|
" modified character with K_SPECIAL byte
|
||||||
|
let &pastetoggle = '<M-…>'
|
||||||
|
call assert_equal('<M-…>', &pastetoggle)
|
||||||
|
call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
|
||||||
|
|
||||||
|
" illegal bytes
|
||||||
|
let str = ":\x7f:\x80:\x90:\xd0:"
|
||||||
|
let &pastetoggle = str
|
||||||
|
call assert_equal(str, &pastetoggle)
|
||||||
|
call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
|
||||||
|
unlet str
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_wildchar()
|
func Test_wildchar()
|
||||||
" Empty 'wildchar' used to access invalid memory.
|
" Empty 'wildchar' used to access invalid memory.
|
||||||
call assert_fails('set wildchar=', 'E521:')
|
call assert_fails('set wildchar=', 'E521:')
|
||||||
|
@ -746,6 +746,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4924,
|
||||||
/**/
|
/**/
|
||||||
4923,
|
4923,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user