|
@@ -4,9 +4,8 @@
|
|
|
|
|
|
#include "../cJSON.h"
|
|
|
|
|
|
-#ifdef __cplusplus
|
|
|
-extern "C"
|
|
|
-#endif
|
|
|
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); /* required by C89 */
|
|
|
+
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|
|
{
|
|
|
cJSON *json;
|
|
@@ -17,6 +16,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|
|
|
|
|
|
|
|
if(size <= offset) return 0;
|
|
|
+ if(data[size-1] != '\0') return 0;
|
|
|
if(data[0] != '1' && data[0] != '0') return 0;
|
|
|
if(data[1] != '1' && data[1] != '0') return 0;
|
|
|
if(data[2] != '1' && data[2] != '0') return 0;
|
|
@@ -27,19 +27,9 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|
|
formatted = data[2] == '1' ? 1 : 0;
|
|
|
buffered = data[3] == '1' ? 1 : 0;
|
|
|
|
|
|
- copied = (unsigned char*)malloc(size);
|
|
|
- if(copied == NULL) return 0;
|
|
|
-
|
|
|
- memcpy(copied, data, size);
|
|
|
- copied[size-1] = '\0';
|
|
|
-
|
|
|
- json = cJSON_ParseWithOpts((const char*)copied + offset, NULL, require_termination);
|
|
|
+ json = cJSON_ParseWithOpts((const char*)data + offset, NULL, require_termination);
|
|
|
|
|
|
- if(json == NULL)
|
|
|
- {
|
|
|
- free(copied);
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ if(json == NULL) return 0;
|
|
|
|
|
|
if(buffered)
|
|
|
{
|
|
@@ -62,11 +52,17 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|
|
|
|
|
if(minify)
|
|
|
{
|
|
|
+ copied = (unsigned char*)malloc(size);
|
|
|
+ if(copied == NULL) return 0;
|
|
|
+
|
|
|
+ memcpy(copied, data, size);
|
|
|
+
|
|
|
cJSON_Minify((char*)copied + offset);
|
|
|
+
|
|
|
+ free(copied);
|
|
|
}
|
|
|
|
|
|
cJSON_Delete(json);
|
|
|
- free(copied);
|
|
|
|
|
|
return 0;
|
|
|
}
|