add fuzz target

This commit is contained in:
Randy 2019-07-11 13:56:07 +02:00
parent 3c8935676a
commit f7f175fdf2
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
#include <stdlib.h>
#include <stdint.h>
#include "../cJSON.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
if((data[0] == '\0') || (size < 3) || (data[1] == '\0')) return 0;
cJSON *json = cJSON_Parse((const char*)data + 2);
if(json == NULL) return 0;
int do_format = 0;
char *printed_json = NULL;
if(data[1] == 'f') do_format = 1;
if(data[0] == 'b')
{
/* buffered printing */
printed_json = cJSON_PrintBuffered(json, 1, do_format);
}
else
{
/* unbuffered printing */
if(do_format)
{
printed_json = cJSON_Print(json);
}
else
{
printed_json = cJSON_PrintUnformatted(json);
}
}
if(printed_json != NULL) free(printed_json);
cJSON_Delete(json);
return 0;
}