From ff0681e4fdc971665c054a942cb015d644c97436 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Mon, 30 Jan 2017 19:30:16 +0100 Subject: [PATCH] Utils: PatchDetach: Check for invalid patch string --- cJSON_Utils.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cJSON_Utils.c b/cJSON_Utils.c index 02eadfc..8b5f4b8 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -234,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); - childptr = strrchr(parentptr, '/'); /* last '/' */ - if (childptr) - { - /* split strings */ - *childptr++ = '\0'; + if (parentptr == NULL) { + return NULL; } + + childptr = strrchr(parentptr, '/'); /* last '/' */ + if (childptr == NULL) + { + free(parentptr); + return NULL; + } + /* split strings */ + *childptr++ = '\0'; + parent = cJSONUtils_GetPointer(object, parentptr); cJSONUtils_InplaceDecodePointerString(childptr);