Patch 8.2.0817

8 views
Skip to first unread message

Bram Moolenaar

unread,
May 24, 2020, 12:45:55 PM5/24/20
to vim...@googlegroups.com

Patch 8.2.0817
Problem: Not enough memory allocated when converting string with special
character.
Solution: Reserve space for modifier code. (closes #6130)
Files: src/eval.c, src/testdir/test_functions.vim


*** ../vim-8.2.0816/src/eval.c 2020-05-16 21:20:08.241327155 +0200
--- src/eval.c 2020-05-24 18:43:32.836083228 +0200
***************
*** 3503,3508 ****
--- 3503,3509 ----
char_u *p;
char_u *name;
int extra = 0;
+ int len;

/*
* Find the end of the string, skipping backslashed characters.
***************
*** 3513,3521 ****
{
++p;
// A "\<x>" form occupies at least 4 characters, and produces up
! // to 6 characters: reserve space for 2 extra
if (*p == '<')
! extra += 2;
}
}

--- 3514,3523 ----
{
++p;
// A "\<x>" form occupies at least 4 characters, and produces up
! // to 9 characters (6 for the char and 3 for a modifier): reserve
! // space for 5 extra.
if (*p == '<')
! extra += 5;
}
}

***************
*** 3536,3542 ****
* Copy the string into allocated memory, handling backslashed
* characters.
*/
! name = alloc(p - *arg + extra);
if (name == NULL)
return FAIL;
rettv->v_type = VAR_STRING;
--- 3538,3545 ----
* Copy the string into allocated memory, handling backslashed
* characters.
*/
! len = (int)(p - *arg + extra);
! name = alloc(len);
if (name == NULL)
return FAIL;
rettv->v_type = VAR_STRING;
***************
*** 3610,3615 ****
--- 3613,3620 ----
if (extra != 0)
{
name += extra;
+ if (name >= rettv->vval.v_string + len)
+ iemsg("get_string_tv() used more space than allocated");
break;
}
// FALLTHROUGH
*** ../vim-8.2.0816/src/testdir/test_functions.vim 2020-05-07 18:43:40.863365992 +0200
--- src/testdir/test_functions.vim 2020-05-24 18:25:45.634973292 +0200
***************
*** 2278,2283 ****
--- 2278,2285 ----
set encoding=utf8
call assert_equal('a', nr2char(97, 1))
call assert_equal('a', nr2char(97, 0))
+
+ call assert_equal("\x80\xfc\b\xf4\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x100000) .. '>"'))
endfunc

" Test for screenattr(), screenchar() and screenchars() functions
*** ../vim-8.2.0816/src/version.c 2020-05-24 17:23:41.838154769 +0200
--- src/version.c 2020-05-24 18:40:30.872604222 +0200
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 817,
/**/

--
hundred-and-one symptoms of being an internet addict:
171. You invent another person and chat with yourself in empty chat rooms.

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages