protobuf-c.c: Better input checks in protobuf_c_message_free_unpacked

Check for NULL message pointer passed to protobuf_c_message_free_unpacked

Closes #177
This commit is contained in:
Oleg Efimov 2015-01-18 20:40:57 +03:00
parent f49fabead4
commit 24182d859f
2 changed files with 12 additions and 0 deletions

View File

@ -3158,10 +3158,14 @@ void
protobuf_c_message_free_unpacked(ProtobufCMessage *message,
ProtobufCAllocator *allocator)
{
if (message == NULL)
return;
const ProtobufCMessageDescriptor *desc = message->descriptor;
unsigned f;
ASSERT_IS_MESSAGE(message);
if (allocator == NULL)
allocator = &protobuf_c__allocator;
message->descriptor = NULL;

View File

@ -1925,6 +1925,12 @@ test_alloc_fail (void)
free (packed);
}
static void
test_free_unpacked_input_check_for_null_message (void)
{
protobuf_c_message_free_unpacked (NULL, NULL);
}
/* This test checks that protobuf decoder is capable of detecting special
cases of incomplete messages. The message should have at least two required
fields field1 and field129 with positions pos1 and pos2 (no matter what the
@ -2225,6 +2231,8 @@ static Test tests[] =
{ "test free unpacked", test_alloc_free_all },
{ "test alloc failure", test_alloc_fail },
{ "test free unpacked input check for null message", test_free_unpacked_input_check_for_null_message },
{ "test required_fields_bitmap", test_required_fields_bitmap },
{ "test field flags", test_field_flags },