Pārlūkot izejas kodu

fix potential NULL dereferences found by coverity

Max Bruckner 8 gadi atpakaļ
vecāks
revīzija
4047de4f6e
2 mainītis faili ar 6 papildinājumiem un 1 dzēšanām
  1. 5 0
      cJSON.c
  2. 1 1
      cJSON_Utils.c

+ 5 - 0
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))
     {

+ 1 - 1
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;