summaryrefslogtreecommitdiff
path: root/test/cmark-fuzz.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-27 23:03:53 +0200
committerGitHub <noreply@github.com>2017-06-27 23:03:53 +0200
commit153116f7fd955bbcfee5fe80996a4619c7a343c3 (patch)
tree8bbe02cdfdd4720cce9c69f2f552775338f66038 /test/cmark-fuzz.c
parent00291fd1811eba348f649f74f4c727625f0be945 (diff)
parenta2f1f76dc38a34d0e3d97f75d1fee527931b6e8a (diff)
Merge pull request #209 from philipturnbull/libFuzzer
Add libFuzzer harness for oss-fuzz
Diffstat (limited to 'test/cmark-fuzz.c')
-rw-r--r--test/cmark-fuzz.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/cmark-fuzz.c b/test/cmark-fuzz.c
new file mode 100644
index 0000000..f09db52
--- /dev/null
+++ b/test/cmark-fuzz.c
@@ -0,0 +1,28 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include "cmark.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ int options = 0;
+ if (size > sizeof(options)) {
+ /* First 4 bytes of input are treated as options */
+ int options = *(const int *)data;
+
+ /* Mask off valid option bits */
+ options = options & (CMARK_OPT_SOURCEPOS | CMARK_OPT_HARDBREAKS | CMARK_OPT_SAFE | CMARK_OPT_NOBREAKS | CMARK_OPT_NORMALIZE | CMARK_OPT_VALIDATE_UTF8 | CMARK_OPT_SMART);
+
+ /* Remainder of input is the markdown */
+ const char *markdown = (const char *)(data + sizeof(options));
+ const size_t markdown_size = size - sizeof(options);
+ cmark_node *doc = cmark_parse_document(markdown, markdown_size, options);
+
+ free(cmark_render_commonmark(doc, options, 80));
+ free(cmark_render_html(doc, options));
+ free(cmark_render_latex(doc, options, 80));
+ free(cmark_render_man(doc, options, 80));
+ free(cmark_render_xml(doc, options));
+
+ cmark_node_free(doc);
+ }
+ return 0;
+}