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

Fix potential null pointer dereference in cJSON_Utils
Fixes #96
This commit is contained in:
Max Bruckner 2017-01-30 19:34:33 +01:00 committed by GitHub
commit e4eadb9a81

View File

@ -208,6 +208,11 @@ cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer)
static void cJSONUtils_InplaceDecodePointerString(char *string) static void cJSONUtils_InplaceDecodePointerString(char *string)
{ {
char *s2 = string; char *s2 = string;
if (string == NULL) {
return;
}
for (; *string; s2++, string++) for (; *string; s2++, 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 */ /* copy path and split it in parent and child */
parentptr = cJSONUtils_strdup(path); parentptr = cJSONUtils_strdup(path);
childptr = strrchr(parentptr, '/'); /* last '/' */ if (parentptr == NULL) {
if (childptr) return NULL;
{
/* split strings */
*childptr++ = '\0';
} }
childptr = strrchr(parentptr, '/'); /* last '/' */
if (childptr == NULL)
{
free(parentptr);
return NULL;
}
/* split strings */
*childptr++ = '\0';
parent = cJSONUtils_GetPointer(object, parentptr); parent = cJSONUtils_GetPointer(object, parentptr);
cJSONUtils_InplaceDecodePointerString(childptr); cJSONUtils_InplaceDecodePointerString(childptr);