summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Korczynski <david@adalogics.com>2023-07-24 04:18:28 -0700
committerEmanuele Torre <torreemanuele6@gmail.com>2023-07-24 13:44:27 +0200
commitcf3c11bde848a0b2a487d78dfcbe5f022d0053ab (patch)
treeebcdec61e296bf4e68e69c9678f01b9427e0e697 /tests
parented334b536fc441fe148d796169b47bda348c812a (diff)
Add compile fuzzer for OSS-Fuzz
Signed-off-by: David Korczynski <david@adalogics.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/jq_fuzz_compile.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/jq_fuzz_compile.c b/tests/jq_fuzz_compile.c
new file mode 100644
index 00000000..91218d6f
--- /dev/null
+++ b/tests/jq_fuzz_compile.c
@@ -0,0 +1,25 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "jq.h"
+
+int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+ // Creat null-terminated string
+ char *null_terminated = (char *)malloc(size + 1);
+ memcpy(null_terminated, (char *)data, size);
+ null_terminated[size] = '\0';
+
+ // Fuzzer entrypoint
+ jq_state *jq = NULL;
+ jq = jq_init();
+ if (jq != NULL) {
+ jq_compile(jq, null_terminated);
+ }
+ jq_teardown(&jq);
+
+ // Free the null-terminated string
+ free(null_terminated);
+
+ return 0;
+}