Skip to content

Commit e2c6037

Browse files
committed
patch 8.0.0216: decoding js style json may fail
Problem: When decoding JSON with a JS style object the JSON test may use a NULL pointer. (Coverity) Solution: Check for a NULL pointer.
1 parent e362c3d commit e2c6037

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/json.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,13 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
629629
key = p = reader->js_buf + reader->js_used;
630630
while (*p != NUL && *p != ':' && *p > ' ')
631631
++p;
632-
cur_item->v_type = VAR_STRING;
633-
cur_item->vval.v_string = vim_strnsave(key, (int)(p - key));
632+
if (cur_item != NULL)
633+
{
634+
cur_item->v_type = VAR_STRING;
635+
cur_item->vval.v_string = vim_strnsave(key, (int)(p - key));
636+
top_item->jd_key = cur_item->vval.v_string;
637+
}
634638
reader->js_used += (int)(p - key);
635-
top_item->jd_key = cur_item->vval.v_string;
636639
}
637640
else
638641
{
@@ -1053,7 +1056,8 @@ json_decode(js_read_T *reader, typval_T *res, int options)
10531056

10541057
/*
10551058
* Decode the JSON from "reader" to find the end of the message.
1056-
* "options" can be JSON_JS or zero;
1059+
* "options" can be JSON_JS or zero.
1060+
* This is only used for testing.
10571061
* Return FAIL if the message has a decoding error.
10581062
* Return MAYBE if the message is truncated, need to read more.
10591063
* This only works reliable if the message contains an object, array or

src/json_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ test_decode_find_end(void)
107107
reader.js_buf = (char_u *)" { ";
108108
assert(json_find_end(&reader, 0) == MAYBE);
109109

110+
/* JS object with white space */
111+
reader.js_buf = (char_u *)" { a : 123 } ";
112+
assert(json_find_end(&reader, JSON_JS) == OK);
113+
reader.js_buf = (char_u *)" { a : ";
114+
assert(json_find_end(&reader, JSON_JS) == MAYBE);
115+
110116
/* array without white space */
111117
reader.js_buf = (char_u *)"[\"a\",123]";
112118
assert(json_find_end(&reader, 0) == OK);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
216,
767769
/**/
768770
215,
769771
/**/

0 commit comments

Comments
 (0)