diff options
author | ZyX <kp-pav@yandex.ru> | 2016-03-07 07:37:21 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:48:20 +0300 |
commit | 224d7df6309319cfa1f98aad3aa93c5b63ee4145 (patch) | |
tree | b9f58278536ecaa67e3e15fb145b7b7e23da4065 /src/nvim/eval/decode.c | |
parent | 394830631f130ad646f23358bf7863e7a37c6d78 (diff) | |
download | rneovim-224d7df6309319cfa1f98aad3aa93c5b63ee4145.tar.gz rneovim-224d7df6309319cfa1f98aad3aa93c5b63ee4145.tar.bz2 rneovim-224d7df6309319cfa1f98aad3aa93c5b63ee4145.zip |
eval/decode: Make sure that blank input does not crash Neovim
Diffstat (limited to 'src/nvim/eval/decode.c')
-rw-r--r-- | src/nvim/eval/decode.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index ce2723147d..4ce47a5e19 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -223,6 +223,15 @@ int json_decode_string(const char *const buf, const size_t len, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { + const char *p = buf; + const char *const e = buf + len; + while (p < e && (*p == ' ' || *p == '\t' || *p == '\n')) { + p++; + } + if (p == e) { + EMSG(_("E474: Attempt to decode a blank string")); + return FAIL; + } vimconv_T conv = { .vc_type = CONV_NONE }; convert_setup(&conv, (char_u *) "utf-8", p_enc); conv.vc_fail = true; @@ -232,11 +241,9 @@ int json_decode_string(const char *const buf, const size_t len, ContainerStack container_stack; kv_init(container_stack); rettv->v_type = VAR_UNKNOWN; - const char *const e = buf + len; bool didcomma = false; bool didcolon = false; bool next_map_special = false; - const char *p = buf; for (; p < e; p++) { json_decode_string_cycle_start: assert(*p == '{' || next_map_special == false); |