提交 e4eadb9a 编写于 作者: M Max Bruckner 提交者: GitHub

Merge pull request #97 from DaveGamble/fix96-null-pointer-dereference

Fix potential null pointer dereference in cJSON_Utils
Fixes #96 
......@@ -208,6 +208,11 @@ cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer)
static void cJSONUtils_InplaceDecodePointerString(char *string)
{
char *s2 = string;
if (string == NULL) {
return;
}
for (; *string; s2++, string++)
{
*s2 = (*string != '~')
......@@ -229,12 +234,19 @@ static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path)
/* copy path and split it in parent and child */
parentptr = cJSONUtils_strdup(path);
if (parentptr == NULL) {
return NULL;
}
childptr = strrchr(parentptr, '/'); /* last '/' */
if (childptr)
if (childptr == NULL)
{
/* split strings */
*childptr++ = '\0';
free(parentptr);
return NULL;
}
/* split strings */
*childptr++ = '\0';
parent = cJSONUtils_GetPointer(object, parentptr);
cJSONUtils_InplaceDecodePointerString(childptr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册