aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-11-07 13:44:36 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-11-07 13:44:49 -0300
commit847d5ffa7c21321765df1021465a20a96de8bfef (patch)
tree8fcf43d4559a0dff5e69598827d6d6a9de332853
parent05ae9781b5d1dbff7bf82051e9ba6f8e3a68953b (diff)
parent4e880f3f0058dce4a2a8d6fafeee2d89fad291d3 (diff)
downloadrneovim-847d5ffa7c21321765df1021465a20a96de8bfef.tar.gz
rneovim-847d5ffa7c21321765df1021465a20a96de8bfef.tar.bz2
rneovim-847d5ffa7c21321765df1021465a20a96de8bfef.zip
Merge PR #1399 'Better handling for invalid msgpack-rpc'
-rw-r--r--src/nvim/msgpack_rpc/channel.c9
-rw-r--r--src/nvim/msgpack_rpc/helpers.c9
2 files changed, 17 insertions, 1 deletions
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c
index 5564bfa1be..aa6008558f 100644
--- a/src/nvim/msgpack_rpc/channel.c
+++ b/src/nvim/msgpack_rpc/channel.c
@@ -436,6 +436,11 @@ static void handle_request(Channel *channel, msgpack_object *request)
&error,
NIL,
&out_buffer));
+ char buf[256];
+ snprintf(buf, sizeof(buf),
+ "Channel %" PRIu64 " sent an invalid message, closing.",
+ channel->id);
+ call_set_error(channel, buf);
return;
}
@@ -491,6 +496,10 @@ static bool channel_write(Channel *channel, WBuffer *buffer)
{
bool success;
+ if (channel->closed) {
+ return false;
+ }
+
if (channel->is_job) {
success = job_write(channel->data.job, buffer);
} else {
diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c
index 4414aadb15..a702d4f256 100644
--- a/src/nvim/msgpack_rpc/helpers.c
+++ b/src/nvim/msgpack_rpc/helpers.c
@@ -377,14 +377,17 @@ void msgpack_rpc_validate(uint64_t *response_id,
// Validate the basic structure of the msgpack-rpc payload
if (req->type != MSGPACK_OBJECT_ARRAY) {
api_set_error(err, Validation, _("Request is not an array"));
+ return;
}
if (req->via.array.size != 4) {
api_set_error(err, Validation, _("Request array size should be 4"));
+ return;
}
if (req->via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
api_set_error(err, Validation, _("Id must be a positive integer"));
+ return;
}
// Set the response id, which is the same as the request
@@ -392,18 +395,22 @@ void msgpack_rpc_validate(uint64_t *response_id,
if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
api_set_error(err, Validation, _("Message type must be an integer"));
+ return;
}
if (req->via.array.ptr[0].via.u64 != 0) {
api_set_error(err, Validation, _("Message type must be 0"));
+ return;
}
if (req->via.array.ptr[2].type != MSGPACK_OBJECT_BIN
&& req->via.array.ptr[2].type != MSGPACK_OBJECT_STR) {
api_set_error(err, Validation, _("Method must be a string"));
+ return;
}
if (req->via.array.ptr[3].type != MSGPACK_OBJECT_ARRAY) {
- api_set_error(err, Validation, _("Paremeters must be an array"));
+ api_set_error(err, Validation, _("Parameters must be an array"));
+ return;
}
}