Skip to content

Fix a null pointer derefernece bug in function field2json#249

Open
mugitya03 wants to merge 1 commit intobaidu:masterfrom
mugitya03:NPD-2
Open

Fix a null pointer derefernece bug in function field2json#249
mugitya03 wants to merge 1 commit intobaidu:masterfrom
mugitya03:NPD-2

Conversation

@mugitya03
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants