mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2025-01-14 01:07:57 +08:00
Merge pull request #358 from ugurkoltuk-adyen/ugurkoltuk-adyen/message_check_fix
Fix a SEGV on on protobuf_c_message_check on messages with 'oneof's inside
This commit is contained in:
commit
a6556fb372
@ -3422,6 +3422,13 @@ protobuf_c_message_check(const ProtobufCMessage *message)
|
||||
ProtobufCType type = f->type;
|
||||
ProtobufCLabel label = f->label;
|
||||
void *field = STRUCT_MEMBER_P (message, f->offset);
|
||||
|
||||
if (f->flags & PROTOBUF_C_FIELD_FLAG_ONEOF) {
|
||||
const uint32_t *oneof_case = STRUCT_MEMBER_P (message, f->quantifier_offset);
|
||||
if (f->id != *oneof_case) {
|
||||
continue; //Do not check if it is an unpopulated oneof member.
|
||||
}
|
||||
}
|
||||
|
||||
if (label == PROTOBUF_C_LABEL_REPEATED) {
|
||||
size_t *quantity = STRUCT_MEMBER_P (message, f->quantifier_offset);
|
||||
|
@ -964,6 +964,15 @@ static void test_oneof_SubMess (void)
|
||||
DO_TEST (&submess, test_optional_submess_42);
|
||||
#undef DO_TEST
|
||||
}
|
||||
|
||||
static void test_oneof_message_check(void)
|
||||
{
|
||||
Foo__TestMessOneof msg = FOO__TEST_MESS_ONEOF__INIT;
|
||||
msg.test_oneof_case = FOO__TEST_MESS_ONEOF__TEST_ONEOF_TEST_STRING;
|
||||
msg.test_string = "Hello, world!";
|
||||
assert(protobuf_c_message_check((ProtobufCMessage *)&msg));
|
||||
}
|
||||
|
||||
static void test_oneof_merge (void)
|
||||
{
|
||||
Foo__TestMessOneof *msg;
|
||||
@ -2260,6 +2269,7 @@ static Test tests[] =
|
||||
{ "test oneof string", test_oneof_string },
|
||||
{ "test oneof bytes", test_oneof_bytes },
|
||||
{ "test oneof SubMess", test_oneof_SubMess },
|
||||
{ "test oneof message check", test_oneof_message_check },
|
||||
{ "test merged oneof unpack", test_oneof_merge },
|
||||
|
||||
{ "test empty repeated" ,test_empty_repeated },
|
||||
|
Loading…
x
Reference in New Issue
Block a user