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:
Robert Edmonds 2019-05-18 17:52:13 -04:00 committed by GitHub
commit a6556fb372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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);

View File

@ -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 },