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