mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2025-01-14 09:17:55 +08:00
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:
parent
f49fabead4
commit
24182d859f
@ -3158,10 +3158,14 @@ void
|
|||||||
protobuf_c_message_free_unpacked(ProtobufCMessage *message,
|
protobuf_c_message_free_unpacked(ProtobufCMessage *message,
|
||||||
ProtobufCAllocator *allocator)
|
ProtobufCAllocator *allocator)
|
||||||
{
|
{
|
||||||
|
if (message == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
const ProtobufCMessageDescriptor *desc = message->descriptor;
|
const ProtobufCMessageDescriptor *desc = message->descriptor;
|
||||||
unsigned f;
|
unsigned f;
|
||||||
|
|
||||||
ASSERT_IS_MESSAGE(message);
|
ASSERT_IS_MESSAGE(message);
|
||||||
|
|
||||||
if (allocator == NULL)
|
if (allocator == NULL)
|
||||||
allocator = &protobuf_c__allocator;
|
allocator = &protobuf_c__allocator;
|
||||||
message->descriptor = NULL;
|
message->descriptor = NULL;
|
||||||
|
@ -1925,6 +1925,12 @@ test_alloc_fail (void)
|
|||||||
free (packed);
|
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
|
/* This test checks that protobuf decoder is capable of detecting special
|
||||||
cases of incomplete messages. The message should have at least two required
|
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
|
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 free unpacked", test_alloc_free_all },
|
||||||
{ "test alloc failure", test_alloc_fail },
|
{ "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 required_fields_bitmap", test_required_fields_bitmap },
|
||||||
|
|
||||||
{ "test field flags", test_field_flags },
|
{ "test field flags", test_field_flags },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user