Utils: PatchDetach: Check for invalid patch string

This commit is contained in:
Max Bruckner 2017-01-30 19:30:16 +01:00
parent a2309a509d
commit ff0681e4fd

View File

@ -234,12 +234,19 @@ static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path)
/* copy path and split it in parent and child */ /* copy path and split it in parent and child */
parentptr = cJSONUtils_strdup(path); parentptr = cJSONUtils_strdup(path);
if (parentptr == NULL) {
return NULL;
}
childptr = strrchr(parentptr, '/'); /* last '/' */ childptr = strrchr(parentptr, '/'); /* last '/' */
if (childptr) if (childptr == NULL)
{ {
free(parentptr);
return NULL;
}
/* split strings */ /* split strings */
*childptr++ = '\0'; *childptr++ = '\0';
}
parent = cJSONUtils_GetPointer(object, parentptr); parent = cJSONUtils_GetPointer(object, parentptr);
cJSONUtils_InplaceDecodePointerString(childptr); cJSONUtils_InplaceDecodePointerString(childptr);