sofa-pbrpc icon indicating copy to clipboard operation
sofa-pbrpc copied to clipboard

Fix a null pointer derefernece bug in function field2json

Open mugitya03 opened this issue 10 months ago • 0 comments

Explanation of the bug

The function parse_msg may return a null value.

static rapidjson::Value* parse_msg(const Message *msg, rapidjson::Value::AllocatorType& allocator)
{
    const Descriptor *d = msg->GetDescriptor();
    if (!d)
        return NULL;
    size_t count = d->field_count();
    rapidjson::Value* root = new rapidjson::Value(rapidjson::kObjectType);
    if (!root)
        return NULL;
    ...

In function field2json, the return value of function parse_msg propagates to the pointer v at line 206 and is dereferenced at line 207 without any check, causing a null pointer dereference bug.

Fix

I add a null value check before dereferencing the pointer v.

mugitya03 avatar Mar 10 '25 01:03 mugitya03