Skip to content

Commit

Permalink
Merge pull request #97 from DaveGamble/fix96-null-pointer-dereference
Browse files Browse the repository at this point in the history
Fix potential null pointer dereference in cJSON_Utils
Fixes #96
  • Loading branch information
FSMaxB authored Jan 30, 2017
2 parents c49ffbf + ff0681e commit e4eadb9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cJSON_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 != '~')
Expand All @@ -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);

Expand Down

0 comments on commit e4eadb9

Please sign in to comment.