mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-28 06:10:53 +08:00
Fix memory corruption by initlizalizing pointer
A memory corruption in protobuf_c_message_free_unpacked happens at the following line: if (message->unknown_fields != NULL) do_free(allocator, message->unknown_fields); The do_free will free ->unknown_fields. This is may be wrong, because protobuf_c_message_unpack uses malloc as the default allocator, allocates rv with malloc. At the end, however, ->unknown_fields is only initialized if there are some. That means if there are no such fields ->unknown_fields is an uninitialized pointer. The patch initializes the pointer to NULL to ensure the check before free is performed on initialized memory in case there is no unknown_field. This fixes https://github.com/protobuf-c/protobuf-c/issues/690 Signed-off-by: Stephan Mueller <smueller@chronox.de>
This commit is contained in:
parent
8c201f6e47
commit
55c8b0dc68
@ -3278,6 +3278,8 @@ protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc,
|
||||
n_unknown * sizeof(ProtobufCMessageUnknownField));
|
||||
if (rv->unknown_fields == NULL)
|
||||
goto error_cleanup;
|
||||
} else {
|
||||
rv->unknown_fields = NULL;
|
||||
}
|
||||
|
||||
/* do real parsing */
|
||||
|
Loading…
x
Reference in New Issue
Block a user