forked from swiftlang/swift-cmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Makefile target and harness to fuzz with libFuzzer
This can be run locally with `make libFuzzer` but the harness will be integrated into oss-fuzz for large-scale fuzzing.
- Loading branch information
1 parent
70a6a16
commit c1dea4e
Showing
6 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash -eu | ||
CMARK_FUZZ="$1" | ||
shift | ||
ASAN_OPTIONS="quarantine_size_mb=10:detect_leaks=1" "${CMARK_FUZZ}" -max_len=256 -timeout=1 -dict=test/fuzzing_dictionary "$@" |