Last active
November 8, 2022 00:54
-
-
Save skeeto/93891c57a83b2562389959926a9cb364 to your computer and use it in GitHub Desktop.
Jsonic fuzz tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fuzz test for Jsonic | |
// $ afl-gcc -m32 -fsanitize=address,undefined fuzz.c jsonic.c | |
// $ afl-fuzz -m800 -iexamples/heroes -oout ./a.out | |
// https://github.com/rohanrhu/jsonic | |
// This is free and unencumbered software released into the public domain. | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "jsonic.h" | |
static int explore(jsonic_node_t *root, char *buf) | |
{ | |
jsonic_node_t *key = 0; | |
switch (root->type) { | |
case JSONIC_NONE: | |
return 1; | |
case JSONIC_OBJECT: | |
for (;;) { | |
key = jsonic_object_iter_kv_free(buf, root, key); | |
if (key->type == JSONIC_NONE) { | |
return 0; | |
} | |
printf("=> %s\n", key->key); | |
if (explore(key, buf)) { | |
return 1; | |
} | |
} | |
case JSONIC_ARRAY: | |
for (;;) { | |
jsonic_node_t *e = jsonic_array_iter_free(buf, root, e, 0); | |
if (e->type == JSONIC_NONE) { | |
return 0; | |
} | |
if (explore(e, buf)) { | |
return 1; | |
} | |
} | |
case JSONIC_STRING: | |
case JSONIC_NUMBER: | |
case JSONIC_BOOLEAN: | |
case JSONIC_NULL: | |
puts(root->val); | |
return 0; | |
} | |
abort(); | |
} | |
int main(void) | |
{ | |
char *buf = malloc(1<<10); | |
int len = fread(buf, 1, (1<<10)-1, stdin); | |
buf[len++] = 0; | |
buf = realloc(buf, len); | |
return explore(jsonic_get_root(buf), buf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is nice just ~70 SLOC 🙀