cmark

My personal build of CMark ✏️

cmark-fuzz.c (1255B)

 1 #include <stdint.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include "cmark.h"
 5 
 6 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
 7   struct __attribute__((packed)) {
 8     int options;
 9     int width;
10   } fuzz_config;
11 
12   if (size >= sizeof(fuzz_config)) {
13     /* The beginning of `data` is treated as fuzzer configuration */
14     memcpy(&fuzz_config, data, sizeof(fuzz_config));
15 
16     /* Mask off valid option bits */
17     fuzz_config.options &= (CMARK_OPT_SOURCEPOS | CMARK_OPT_HARDBREAKS | CMARK_OPT_UNSAFE | CMARK_OPT_NOBREAKS | CMARK_OPT_NORMALIZE | CMARK_OPT_VALIDATE_UTF8 | CMARK_OPT_SMART);
18 
19     /* Remainder of input is the markdown */
20     const char *markdown = (const char *)(data + sizeof(fuzz_config));
21     const size_t markdown_size = size - sizeof(fuzz_config);
22     cmark_node *doc = cmark_parse_document(markdown, markdown_size, fuzz_config.options);
23 
24     free(cmark_render_commonmark(doc, fuzz_config.options, fuzz_config.width));
25     free(cmark_render_html(doc, fuzz_config.options));
26     free(cmark_render_latex(doc, fuzz_config.options, fuzz_config.width));
27     free(cmark_render_man(doc, fuzz_config.options, fuzz_config.width));
28     free(cmark_render_xml(doc, fuzz_config.options));
29 
30     cmark_node_free(doc);
31   }
32   return 0;
33 }