]> granicus.if.org Git - vim/commitdiff
patch 9.0.0052: "zG" may throw an error if invalid character follows v9.0.0052
authorK.Takata <kentkt@csc.jp>
Thu, 14 Jul 2022 16:25:14 +0000 (17:25 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 14 Jul 2022 16:25:14 +0000 (17:25 +0100)
Problem:    "zG" may throw an error if invalid character follows.
Solution:   Pass the word length to valid_spell_word(). (Ken Takata,
            closes #10737)

src/spellfile.c
src/testdir/test_spell.vim
src/version.c

index 4a0de5237ffea85b5c5ed5e9341efb3c5b28842a..8120d75bf90ba961a1937635e74f902111aaf56a 100644 (file)
@@ -4371,13 +4371,13 @@ wordtree_alloc(spellinfo_T *spin)
  * Control characters and trailing '/' are invalid.  Space is OK.
  */
     static int
-valid_spell_word(char_u *word)
+valid_spell_word(char_u *word, char_u *end)
 {
     char_u *p;
 
-    if (enc_utf8 && !utf_valid_string(word, NULL))
+    if (enc_utf8 && !utf_valid_string(word, end))
        return FALSE;
-    for (p = word; *p != NUL; p += mb_ptr2len(p))
+    for (p = word; *p != NUL && p < end; p += mb_ptr2len(p))
        if (*p < ' ' || (p[0] == '/' && p[1] == NUL))
            return FALSE;
     return TRUE;
@@ -4408,7 +4408,7 @@ store_word(
     char_u     *p;
 
     // Avoid adding illegal bytes to the word tree.
-    if (!valid_spell_word(word))
+    if (!valid_spell_word(word, word + len))
        return FAIL;
 
     (void)spell_casefold(curwin, word, len, foldword, MAXWLEN);
@@ -6211,7 +6211,7 @@ spell_add_word(
     int                i;
     char_u     *spf;
 
-    if (!valid_spell_word(word))
+    if (!valid_spell_word(word, word + len))
     {
        emsg(_(e_illegal_character_in_word));
        return;
index a291eb5c7a4d62363a9ad5ef4e14ad42a99c4f59..94ea3d7fe2bde6aae048d12598737cc472741e0f 100644 (file)
@@ -884,6 +884,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)
   set enc=latin1
   set spellfile=
index a6a80b6719be18a7b477dab9bbfd02bcd6ea53dd..3c4e96cf3c6b1f336b35f59af0031af13f1c4fa5 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    52,
 /**/
     51,
 /**/