diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-07-01 22:26:20 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-07-01 22:26:20 +0100 |
commit | 5e59ea54c0c37c2f84770f068d95280069828774 (patch) | |
tree | 09f0c34da420d6aff84c745647201844c15fcfab /src/spellfile.c | |
parent | f12129f1714f7d2301935bb21d896609bdac221c (diff) | |
download | vim-git-5e59ea54c0c37c2f84770f068d95280069828774.tar.gz |
patch 9.0.0021: invalid memory access when adding word to spell word listv9.0.0021
Problem: Invalid memory access when adding word with a control character to
the internal spell word list.
Solution: Disallow adding a word with control characters or a trailing
slash.
Diffstat (limited to 'src/spellfile.c')
-rw-r--r-- | src/spellfile.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/spellfile.c b/src/spellfile.c index f0d6d96a4..4a0de5237 100644 --- a/src/spellfile.c +++ b/src/spellfile.c @@ -4367,6 +4367,23 @@ wordtree_alloc(spellinfo_T *spin) } /* + * Return TRUE if "word" contains valid word characters. + * Control characters and trailing '/' are invalid. Space is OK. + */ + static int +valid_spell_word(char_u *word) +{ + char_u *p; + + if (enc_utf8 && !utf_valid_string(word, NULL)) + return FALSE; + for (p = word; *p != NUL; p += mb_ptr2len(p)) + if (*p < ' ' || (p[0] == '/' && p[1] == NUL)) + return FALSE; + return TRUE; +} + +/* * Store a word in the tree(s). * Always store it in the case-folded tree. For a keep-case word this is * useful when the word can also be used with all caps (no WF_FIXCAP flag) and @@ -4391,7 +4408,7 @@ store_word( char_u *p; // Avoid adding illegal bytes to the word tree. - if (enc_utf8 && !utf_valid_string(word, NULL)) + if (!valid_spell_word(word)) return FAIL; (void)spell_casefold(curwin, word, len, foldword, MAXWLEN); @@ -6194,7 +6211,7 @@ spell_add_word( int i; char_u *spf; - if (enc_utf8 && !utf_valid_string(word, NULL)) + if (!valid_spell_word(word)) { emsg(_(e_illegal_character_in_word)); return; |