mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.1188: memory leak with invalid json input
Problem: Memory leak with invalid json input. Solution: Free all keys at the end. (Dominique Pellé, closes #6443, closes #6442)
This commit is contained in:
parent
c85156bb89
commit
6d3a7213f5
@ -594,6 +594,7 @@ typedef struct {
|
|||||||
json_decode_item(js_read_T *reader, typval_T *res, int options)
|
json_decode_item(js_read_T *reader, typval_T *res, int options)
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
int i;
|
||||||
int len;
|
int len;
|
||||||
int retval;
|
int retval;
|
||||||
garray_T stack;
|
garray_T stack;
|
||||||
@ -621,9 +622,6 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
|
|||||||
if (*p == NUL)
|
if (*p == NUL)
|
||||||
{
|
{
|
||||||
retval = MAYBE;
|
retval = MAYBE;
|
||||||
if (top_item->jd_type == JSON_OBJECT)
|
|
||||||
// did get the key, clear it
|
|
||||||
clear_tv(&top_item->jd_key_tv);
|
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
if (top_item->jd_type == JSON_OBJECT_KEY
|
if (top_item->jd_type == JSON_OBJECT_KEY
|
||||||
@ -925,7 +923,6 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
|
|||||||
top_item->jd_key = tv_get_string_buf_chk(cur_item, key_buf);
|
top_item->jd_key = tv_get_string_buf_chk(cur_item, key_buf);
|
||||||
if (top_item->jd_key == NULL)
|
if (top_item->jd_key == NULL)
|
||||||
{
|
{
|
||||||
clear_tv(cur_item);
|
|
||||||
emsg(_(e_invarg));
|
emsg(_(e_invarg));
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
goto theend;
|
goto theend;
|
||||||
@ -1001,7 +998,6 @@ item_end:
|
|||||||
{
|
{
|
||||||
semsg(_("E938: Duplicate key in JSON: \"%s\""),
|
semsg(_("E938: Duplicate key in JSON: \"%s\""),
|
||||||
top_item->jd_key);
|
top_item->jd_key);
|
||||||
clear_tv(&top_item->jd_key_tv);
|
|
||||||
clear_tv(cur_item);
|
clear_tv(cur_item);
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
goto theend;
|
goto theend;
|
||||||
@ -1060,7 +1056,10 @@ item_end:
|
|||||||
semsg(_(e_json_error), p);
|
semsg(_(e_json_error), p);
|
||||||
|
|
||||||
theend:
|
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);
|
ga_clear(&stack);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +201,8 @@ func Test_json_decode()
|
|||||||
call assert_fails('call json_decode("\"\\u111Z\"")', 'E491:')
|
call assert_fails('call json_decode("\"\\u111Z\"")', 'E491:')
|
||||||
call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
|
call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
|
||||||
call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))
|
call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))
|
||||||
|
|
||||||
|
call assert_fails('call json_decode("{\"\":{\"\":{")', 'E491:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let s:jsl5 = '[7,,,]'
|
let s:jsl5 = '[7,,,]'
|
||||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1188,
|
||||||
/**/
|
/**/
|
||||||
1187,
|
1187,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user