diff options
author | James McCoy <jamessan@jamessan.com> | 2017-03-10 17:26:22 -0500 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2017-03-11 20:32:38 -0500 |
commit | 2ed2b1d505cc028347b579f677eb8e6bde9dacdd (patch) | |
tree | 90636600427eae51716a16beb659fe7dd8cb2192 /src/nvim/getchar.c | |
parent | eaf1f9b9dc62b2201fa54374a88029de1b3f94fb (diff) | |
download | rneovim-2ed2b1d505cc028347b579f677eb8e6bde9dacdd.tar.gz rneovim-2ed2b1d505cc028347b579f677eb8e6bde9dacdd.tar.bz2 rneovim-2ed2b1d505cc028347b579f677eb8e6bde9dacdd.zip |
vim-patch:7.4.2223
Problem: Buffer overflow when using latin1 character with feedkeys().
Solution: Check for an illegal character. Add a test.
https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Diffstat (limited to 'src/nvim/getchar.c')
-rw-r--r-- | src/nvim/getchar.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 46c1e89c31..2a5454cb92 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3746,8 +3746,10 @@ eval_map_expr ( */ char_u *vim_strsave_escape_csi(char_u *p) { - /* Need a buffer to hold up to three times as much. */ - char_u *res = xmalloc(STRLEN(p) * 3 + 1); + // Need a buffer to hold up to three times as much. Four in case of an + // illegal utf-8 byte: + // 0xc0 -> 0xc3 - 0x80 -> 0xc3 K_SPECIAL KS_SPECIAL KE_FILLER + char_u *res = xmalloc(STRLEN(p) * 4 + 1); char_u *d = res; for (char_u *s = p; *s != NUL; ) { if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) { @@ -3756,17 +3758,10 @@ char_u *vim_strsave_escape_csi(char_u *p) *d++ = *s++; *d++ = *s++; } else { - int len = mb_char2len(PTR2CHAR(s)); - int len2 = mb_ptr2len(s); - /* Add character, possibly multi-byte to destination, escaping - * CSI and K_SPECIAL. */ + // Add character, possibly multi-byte to destination, escaping + // CSI and K_SPECIAL. Be careful, it can be an illegal byte! d = add_char2buf(PTR2CHAR(s), d); - while (len < len2) { - /* add following combining char */ - d = add_char2buf(PTR2CHAR(s + len), d); - len += mb_char2len(PTR2CHAR(s + len)); - } - mb_ptr_adv(s); + s += MB_CPTR2LEN(s); } } *d = NUL; |