sofa-pbrpc
sofa-pbrpc copied to clipboard
Fix a null pointer derefernece bug in function field2json
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.