msgpack-rpc: handle failure to convert method arguments #2664

This commit is contained in:
Björn Linse
2015-05-15 16:01:53 +02:00
parent 90fae3663f
commit 5bbd182a3e
2 changed files with 16 additions and 1 deletions

View File

@@ -464,7 +464,11 @@ static void handle_request(Channel *channel, msgpack_object *request)
} }
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
msgpack_rpc_to_array(msgpack_rpc_args(request), &args); if (!msgpack_rpc_to_array(msgpack_rpc_args(request), &args)) {
handler.fn = msgpack_rpc_handle_invalid_arguments;
handler.defer = false;
}
bool defer = (!kv_size(channel->call_stack) && handler.defer); bool defer = (!kv_size(channel->call_stack) && handler.defer);
RequestEvent *event_data = xmalloc(sizeof(RequestEvent)); RequestEvent *event_data = xmalloc(sizeof(RequestEvent));
event_data->channel = channel; event_data->channel = channel;

View File

@@ -306,6 +306,17 @@ Object msgpack_rpc_handle_missing_method(uint64_t channel_id,
return NIL; return NIL;
} }
/// Handler executed when malformated arguments are passed
Object msgpack_rpc_handle_invalid_arguments(uint64_t channel_id,
uint64_t request_id,
Array args,
Error *error)
{
snprintf(error->msg, sizeof(error->msg), "Invalid method arguments");
error->set = true;
return NIL;
}
/// Serializes a msgpack-rpc request or notification(id == 0) /// Serializes a msgpack-rpc request or notification(id == 0)
void msgpack_rpc_serialize_request(uint64_t request_id, void msgpack_rpc_serialize_request(uint64_t request_id,
String method, String method,