From 4047de4f6e0c86db54a45c624543d43100340dbb Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 8 Feb 2017 03:00:44 +0100 Subject: [PATCH] fix potential NULL dereferences found by coverity --- cJSON.c | 5 +++++ cJSON_Utils.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 13d5a02..b16abae 100644 --- a/cJSON.c +++ b/cJSON.c @@ -167,6 +167,11 @@ static const unsigned char *parse_number(cJSON *item, const unsigned char *num) double number = 0; unsigned char *endpointer = NULL; + if (num == NULL) + { + return NULL; + } + number = strtod((const char*)num, (char**)&endpointer); if ((num == endpointer) || (num == NULL)) { diff --git a/cJSON_Utils.c b/cJSON_Utils.c index 378a3e3..ccc250a 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -277,7 +277,7 @@ static cJSON *cJSONUtils_PatchDetach(cJSON *object, const unsigned char *path) static int cJSONUtils_Compare(cJSON *a, cJSON *b) { - if ((a->type & 0xFF) != (b->type & 0xFF)) + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) { /* mismatched type. */ return -1;