Skip to content

Commit

Permalink
Add NULL check to deserializer functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Zeisberg committed Mar 14, 2016
1 parent a45a580 commit eac72b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/rpc/msgpack/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ int message_serialize_error_response(msgpack_packer *pk,
int message_serialize_response(struct message_response *res,
msgpack_packer *pk)
{
msgpack_pack_array(pk, 4);

if (pack_uint8(pk, MESSAGE_TYPE_RESPONSE) == -1)
if (!pk || !res)
return (-1);

msgpack_pack_array(pk, 4);
pack_uint8(pk, MESSAGE_TYPE_RESPONSE);
pack_uint32(pk, res->msgid);
pack_nil(pk);

Expand All @@ -121,11 +121,11 @@ int message_serialize_response(struct message_response *res,
int message_serialize_request(struct message_request *req,
msgpack_packer *pk)
{
msgpack_pack_array(pk, 4);

if (pack_uint8(pk, MESSAGE_TYPE_REQUEST) == -1)
if (!pk || !req)
return (-1);

msgpack_pack_array(pk, 4);
pack_uint8(pk, MESSAGE_TYPE_REQUEST);
pack_uint32(pk, req->msgid);

if (req->method.str == NULL || (pack_string(pk, req->method) == -1))
Expand Down
3 changes: 3 additions & 0 deletions test/unit/message-serialize-request.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ void unit_message_serialize_request(UNUSED(void **state))

free_params(request.params);

/* null check */
assert_int_not_equal(0, message_serialize_request(NULL, NULL));

msgpack_sbuffer_destroy(&sbuf);
}
5 changes: 4 additions & 1 deletion test/unit/message-serialize-response.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ void unit_message_serialize_response(UNUSED(void **state))
response.params = params;
assert_int_not_equal(0, message_serialize_response(&response, &pk));
msgpack_sbuffer_clear(&sbuf);

free_params(response.params);

/* null check */
assert_int_not_equal(0, message_serialize_response(NULL, NULL));

msgpack_sbuffer_destroy(&sbuf);
}

0 comments on commit eac72b8

Please sign in to comment.