Mercurial > vim
comparison src/json.c @ 10652:bb4360d64eb2 v8.0.0216
patch 8.0.0216: decoding js style json may fail
commit https://github.com/vim/vim/commit/e2c6037da387aad05e4f6bd4a8a6267051d6de04
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 22 15:56:26 2017 +0100
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.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 22 Jan 2017 16:00:04 +0100 |
parents | dffda1f9b501 |
children | 287049007bbc |
comparison
equal
deleted
inserted
replaced
10651:a95230501320 | 10652:bb4360d64eb2 |
---|---|
627 | 627 |
628 /* accept an object key that is not in quotes */ | 628 /* accept an object key that is not in quotes */ |
629 key = p = reader->js_buf + reader->js_used; | 629 key = p = reader->js_buf + reader->js_used; |
630 while (*p != NUL && *p != ':' && *p > ' ') | 630 while (*p != NUL && *p != ':' && *p > ' ') |
631 ++p; | 631 ++p; |
632 cur_item->v_type = VAR_STRING; | 632 if (cur_item != NULL) |
633 cur_item->vval.v_string = vim_strnsave(key, (int)(p - key)); | 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 } | |
634 reader->js_used += (int)(p - key); | 638 reader->js_used += (int)(p - key); |
635 top_item->jd_key = cur_item->vval.v_string; | |
636 } | 639 } |
637 else | 640 else |
638 { | 641 { |
639 switch (*p) | 642 switch (*p) |
640 { | 643 { |
1051 return ret; | 1054 return ret; |
1052 } | 1055 } |
1053 | 1056 |
1054 /* | 1057 /* |
1055 * Decode the JSON from "reader" to find the end of the message. | 1058 * 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. | |
1057 * Return FAIL if the message has a decoding error. | 1061 * Return FAIL if the message has a decoding error. |
1058 * Return MAYBE if the message is truncated, need to read more. | 1062 * Return MAYBE if the message is truncated, need to read more. |
1059 * This only works reliable if the message contains an object, array or | 1063 * This only works reliable if the message contains an object, array or |
1060 * string. A number might be trucated without knowing. | 1064 * string. A number might be trucated without knowing. |
1061 * Does not advance the reader. | 1065 * Does not advance the reader. |