aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-15 08:42:36 +0800
committerGitHub <noreply@github.com>2022-07-15 08:42:36 +0800
commit072fb55cb04c03e0ec2d7378ee845d8fd96b2697 (patch)
treed279a982ba72838da0d1344d70f082fff6bcc06b
parent75ad050919b1d27f90b5e6332b9d446529c7cb31 (diff)
downloadrneovim-072fb55cb04c03e0ec2d7378ee845d8fd96b2697.tar.gz
rneovim-072fb55cb04c03e0ec2d7378ee845d8fd96b2697.tar.bz2
rneovim-072fb55cb04c03e0ec2d7378ee845d8fd96b2697.zip
vim-patch:9.0.0052: "zG" may throw an error if invalid character follows (#19368)
Problem: "zG" may throw an error if invalid character follows. Solution: Pass the word length to valid_spell_word(). (Ken Takata, closes vim/vim#10737) https://github.com/vim/vim/commit/2ebcc35826bc2deb04e5fc6d73332f55783e7f52
-rw-r--r--src/nvim/spellfile.c10
-rw-r--r--src/nvim/testdir/test_spell.vim10
2 files changed, 15 insertions, 5 deletions
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 04eb9dd2bc..9d2fd2637d 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -3905,12 +3905,12 @@ static wordnode_T *wordtree_alloc(spellinfo_T *spin)
/// Return true if "word" contains valid word characters.
/// Control characters and trailing '/' are invalid. Space is OK.
-static bool valid_spell_word(const char_u *word)
+static bool valid_spell_word(const char_u *word, const char_u *end)
{
- if (!utf_valid_string(word, NULL)) {
+ if (!utf_valid_string(word, end)) {
return false;
}
- for (const char_u *p = word; *p != NUL; p += utfc_ptr2len((const char *)p)) {
+ for (const char_u *p = word; *p != NUL && p < end; p += utfc_ptr2len((const char *)p)) {
if (*p < ' ' || (p[0] == '/' && p[1] == NUL)) {
return false;
}
@@ -3939,7 +3939,7 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co
int res = OK;
// Avoid adding illegal bytes to the word tree.
- if (!valid_spell_word(word)) {
+ if (!valid_spell_word(word, word + len)) {
return FAIL;
}
@@ -5536,7 +5536,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo
int i;
char_u *spf;
- if (!valid_spell_word(word)) {
+ if (!valid_spell_word(word, word + len)) {
emsg(_(e_illegal_character_in_word));
return;
}
diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim
index 58f0760f48..7744c5bcca 100644
--- a/src/nvim/testdir/test_spell.vim
+++ b/src/nvim/testdir/test_spell.vim
@@ -827,6 +827,16 @@ func Test_spell_good_word_invalid()
bwipe!
endfunc
+func Test_spell_good_word_slash()
+ " This caused E1280.
+ new
+ norm afoo /
+ 1
+ norm zG
+
+ bwipe!
+endfunc
+
func LoadAffAndDic(aff_contents, dic_contents)
throw 'skipped: Nvim does not support enc=latin1'
set enc=latin1