diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-06-03 11:51:31 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-06-03 12:01:24 +0200 |
commit | 72644448732f9b598531460ade793d42ab08081e (patch) | |
tree | fd8b47ce0fc5cf06853e5ee12881db767070a901 | |
parent | 9745941ef620da86bf18f965f85e8fc2ce8206b5 (diff) | |
download | rneovim-72644448732f9b598531460ade793d42ab08081e.tar.gz rneovim-72644448732f9b598531460ade793d42ab08081e.tar.bz2 rneovim-72644448732f9b598531460ade793d42ab08081e.zip |
fix(api): some robustness issues in api_parse_enter
-rw-r--r-- | src/nvim/msgpack_rpc/unpacker.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/nvim/msgpack_rpc/unpacker.c b/src/nvim/msgpack_rpc/unpacker.c index 9db8f314bf..e60d9f220f 100644 --- a/src/nvim/msgpack_rpc/unpacker.c +++ b/src/nvim/msgpack_rpc/unpacker.c @@ -50,15 +50,23 @@ static void api_parse_enter(mpack_parser_t *parser, mpack_node_t *node) Object *obj = parent->data[0].p; KeyValuePair *kv = &kv_A(obj->data.dictionary, parent->pos); if (!parent->key_visited) { + // TODO(bfredl): when implementing interrupt parse on error, + // stop parsing here when node is not a STR/BIN + kv->key = (String)STRING_INIT; key_location = &kv->key; - } else { - result = &kv->value; } + result = &kv->value; break; } - default: + case MPACK_TOKEN_STR: + case MPACK_TOKEN_BIN: + case MPACK_TOKEN_EXT: + assert(node->tok.type == MPACK_TOKEN_CHUNK); break; + + default: + abort(); } } else { result = &unpacker->result; @@ -99,6 +107,7 @@ static void api_parse_enter(mpack_parser_t *parser, mpack_node_t *node) break; case MPACK_TOKEN_CHUNK: + assert(parent); if (parent->tok.type == MPACK_TOKEN_STR || parent->tok.type == MPACK_TOKEN_BIN) { char *data = parent->data[0].p; memcpy(data + parent->pos, |