Patch 8.2.1188
Problem:    Memory leak with invalid json input.
Solution:   Free all keys at the end. (Dominique Pellé, closes #6443,
            closes #6442)
Files:      src/json.c, src/testdir/test_json.vim


*** ../vim-8.2.1187/src/json.c  2020-06-12 22:59:07.266097201 +0200
--- src/json.c  2020-07-12 14:32:41.455358967 +0200
***************
*** 594,599 ****
--- 594,600 ----
  json_decode_item(js_read_T *reader, typval_T *res, int options)
  {
      char_u    *p;
+     int               i;
      int               len;
      int               retval;
      garray_T  stack;
***************
*** 621,629 ****
            if (*p == NUL)
            {
                retval = MAYBE;
-               if (top_item->jd_type == JSON_OBJECT)
-                   // did get the key, clear it
-                   clear_tv(&top_item->jd_key_tv);
                goto theend;
            }
            if (top_item->jd_type == JSON_OBJECT_KEY
--- 622,627 ----
***************
*** 925,931 ****
                top_item->jd_key = tv_get_string_buf_chk(cur_item, key_buf);
                if (top_item->jd_key == NULL)
                {
-                   clear_tv(cur_item);
                    emsg(_(e_invarg));
                    retval = FAIL;
                    goto theend;
--- 923,928 ----
***************
*** 1001,1007 ****
                {
                    semsg(_("E938: Duplicate key in JSON: \"%s\""),
                                                             top_item->jd_key);
-                   clear_tv(&top_item->jd_key_tv);
                    clear_tv(cur_item);
                    retval = FAIL;
                    goto theend;
--- 998,1003 ----
***************
*** 1060,1066 ****
--- 1056,1065 ----
      semsg(_(e_json_error), p);
  
  theend:
+     for (i = 0; i < stack.ga_len; i++)
+       clear_tv(&(((json_dec_item_T *)stack.ga_data) + i)->jd_key_tv);
      ga_clear(&stack);
+ 
      return retval;
  }
  
*** ../vim-8.2.1187/src/testdir/test_json.vim   2020-07-11 22:14:54.314422214 
+0200
--- src/testdir/test_json.vim   2020-07-12 14:28:00.915743924 +0200
***************
*** 201,206 ****
--- 201,208 ----
    call assert_fails('call json_decode("\"\\u111Z\"")', 'E491:')
    call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
    call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))
+ 
+   call assert_fails('call json_decode("{\"\":{\"\":{")', 'E491:')
  endfunc
  
  let s:jsl5 = '[7,,,]'
*** ../vim-8.2.1187/src/version.c       2020-07-12 14:09:19.480092872 +0200
--- src/version.c       2020-07-12 14:29:14.687654931 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1188,
  /**/

-- 
Me?  A skeptic?  I trust you have proof.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202007121234.06CCYXXj2467291%40masaka.moolenaar.net.

Raspunde prin e-mail lui