cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit e4eadb9a81e9e3bcde2b335a5a7297ce1369c856
parent c49ffbfba82bb1404bc9bab46922c6c169da2322
Author: Max Bruckner <max@maxbruckner.de>
Date:   Mon, 30 Jan 2017 19:34:33 +0100

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

Fix potential null pointer dereference in cJSON_Utils
Fixes #96 
Diffstat:
McJSON_Utils.c | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/cJSON_Utils.c b/cJSON_Utils.c @@ -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);