2020-04-13 16:33:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <janet.h>
|
|
|
|
|
2020-04-17 18:39:23 +00:00
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
2020-04-18 21:04:26 +00:00
|
|
|
|
2020-04-19 19:36:38 +00:00
|
|
|
/* init Janet */
|
|
|
|
janet_init();
|
2020-04-18 21:04:26 +00:00
|
|
|
|
2020-04-19 19:36:38 +00:00
|
|
|
/* fuzz the parser */
|
|
|
|
JanetParser parser;
|
|
|
|
janet_parser_init(&parser);
|
|
|
|
for (int i=0, done = 0; i < size; i++)
|
2020-04-18 21:04:26 +00:00
|
|
|
{
|
2020-04-19 19:36:38 +00:00
|
|
|
switch (janet_parser_status(&parser)) {
|
|
|
|
case JANET_PARSE_DEAD:
|
|
|
|
case JANET_PARSE_ERROR:
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
case JANET_PARSE_PENDING:
|
|
|
|
if (i == size) {
|
|
|
|
janet_parser_eof(&parser);
|
|
|
|
} else {
|
|
|
|
janet_parser_consume(&parser, data[i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case JANET_PARSE_ROOT:
|
|
|
|
if (i >= size) {
|
|
|
|
janet_parser_eof(&parser);
|
|
|
|
} else {
|
|
|
|
janet_parser_consume(&parser, data[i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (done == 1)
|
|
|
|
break;
|
2020-04-18 21:04:26 +00:00
|
|
|
}
|
2020-04-19 19:36:38 +00:00
|
|
|
janet_parser_deinit(&parser);
|
2020-04-13 16:33:58 +00:00
|
|
|
|
2020-04-19 19:36:38 +00:00
|
|
|
/* cleanup Janet */
|
2020-04-17 18:39:23 +00:00
|
|
|
janet_deinit();
|
2020-04-13 16:33:58 +00:00
|
|
|
|
2020-04-17 18:39:23 +00:00
|
|
|
return 0;
|
2020-04-13 16:33:58 +00:00
|
|
|
}
|
|
|
|
|