From 63bb7198dfded8a5c37195ebc8503516a1eda0f3 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Mon, 15 Jan 2018 19:27:10 +0800 Subject: [PATCH] vim-patch:8.0.0398: illegal memory access with "t" Problem: Illegal memory access with "t". Solution: Use strncmp() instead of memcmp(). (Dominique Pelle, closes vim/vim#1528) https://github.com/vim/vim/commit/66727e16079fbac6db3897b5c3736ec9fba995bb --- src/nvim/search.c | 8 ++++---- src/nvim/testdir/test_search.vim | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/nvim/search.c b/src/nvim/search.c index 1eb1a25a19..0a266382ec 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1382,13 +1382,13 @@ int searchc(cmdarg_T *cap, int t_cmd) col -= (*mb_head_off)(p, p + col - 1) + 1; } if (lastc_bytelen == 1) { - if (p[col] == c && stop) + if (p[col] == c && stop) { break; - } else { - if (memcmp(p + col, lastc_bytes, lastc_bytelen) == 0 && stop) + } + } else if (STRNCMP(p + col, lastc_bytes, lastc_bytelen) == 0 && stop) { break; } - stop = TRUE; + stop = true; } } else { for (;; ) { diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index a333e7f206..03112df46f 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -298,3 +298,10 @@ func Test_searchpair() q! endfunc +func Test_searchc() + " These commands used to cause memory overflow in searchc(). + new + norm ixx + exe "norm 0t\u93cf" + bw! +endfunc