mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
update fuzzer
This commit is contained in:
parent
2691e142f4
commit
e6bc5d16e6
@ -19,9 +19,19 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|||||||
int formatted = data[2] == '1' ? 1 : 0;
|
int formatted = data[2] == '1' ? 1 : 0;
|
||||||
int buffered = data[3] == '1' ? 1 : 0;
|
int buffered = data[3] == '1' ? 1 : 0;
|
||||||
|
|
||||||
cJSON *json = cJSON_ParseWithOpts((const char*)data + offset, NULL, require_termination);
|
unsigned char *copied = (unsigned char*)malloc(size);
|
||||||
|
if(copied == NULL) return 0;
|
||||||
|
|
||||||
if(json == NULL) return 0;
|
memcpy(copied, data, size);
|
||||||
|
copied[size-1] = '\0';
|
||||||
|
|
||||||
|
cJSON *json = cJSON_ParseWithOpts((const char*)copied + offset, NULL, require_termination);
|
||||||
|
|
||||||
|
if(json == NULL)
|
||||||
|
{
|
||||||
|
free(copied);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char *printed_json = NULL;
|
char *printed_json = NULL;
|
||||||
|
|
||||||
@ -46,16 +56,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|||||||
|
|
||||||
if(minify)
|
if(minify)
|
||||||
{
|
{
|
||||||
unsigned char *copied = (unsigned char*)malloc(size);
|
cJSON_Minify((char*)copied + offset);
|
||||||
|
|
||||||
memcpy(copied, data + offset, size);
|
|
||||||
|
|
||||||
cJSON_Minify((char*)printed_json);
|
|
||||||
free(copied);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
free(copied);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user