소스 검색

Utils: PatchDetach: Check for invalid patch string

Max Bruckner 8 년 전
부모
커밋
ff0681e4fd
1개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 10 3
      cJSON_Utils.c

+ 10 - 3
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);
+    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);