-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use "cmake . -DLEXBOR_BUILD_WITH_FUZZER=ON".
- Loading branch information
1 parent
7cfc4b4
commit 710d76e
Showing
8 changed files
with
214 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
################ | ||
## Search and Includes | ||
######################### | ||
include_directories(".") | ||
|
||
################ | ||
## Sources | ||
######################### | ||
file(GLOB_RECURSE FUZZ_LEXBOR_ENCODING_SOURCES "*.c") | ||
|
||
################ | ||
## Create | ||
######################### | ||
EXECUTABLE_LIST("fuzz_lexbor_encoding_" "${FUZZ_LEXBOR_ENCODING_SOURCES}" ${TEST_UNIT_LIB_NAME} ${LEXBOR_LIB_NAME}) |
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,16 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
################ | ||
## Search and Includes | ||
######################### | ||
include_directories(".") | ||
|
||
################ | ||
## Sources | ||
######################### | ||
file(GLOB_RECURSE FUZZ_LEXBOR_HTML_SOURCES "*.c") | ||
|
||
################ | ||
## Create | ||
######################### | ||
EXECUTABLE_LIST("fuzz_lexbor_html_" "${FUZZ_LEXBOR_HTML_SOURCES}" ${TEST_UNIT_LIB_NAME} ${LEXBOR_LIB_NAME}) |
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,72 @@ | ||
#include <lexbor/html/html.h> | ||
|
||
|
||
#ifndef LEXBOR_HAVE_FUZZER | ||
int | ||
main(int argc, const char *argv[]) | ||
{ | ||
size_t size; | ||
lxb_status_t status; | ||
lxb_html_document_t *document; | ||
char inbuf[4096]; | ||
|
||
document = lxb_html_document_create(); | ||
if (document == NULL) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
status = lxb_html_document_parse_chunk_begin(document); | ||
if (status != LXB_STATUS_OK) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
do { | ||
size = fread(inbuf, 1, sizeof(inbuf), stdin); | ||
if (size != sizeof(inbuf)) { | ||
if (feof(stdin)) { | ||
loop = false; | ||
} | ||
else { | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
status = lxb_html_document_parse_chunk(document, | ||
(const lxb_char_t *) inbuf, size); | ||
if (status != LXB_STATUS_OK) { | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
while (loop); | ||
|
||
status = lxb_html_document_parse_chunk_end(document); | ||
if (status != LXB_STATUS_OK) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
lxb_html_document_destroy(document); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
#endif | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t length) | ||
{ | ||
lxb_status_t status; | ||
lxb_html_document_t *document; | ||
|
||
document = lxb_html_document_create(); | ||
if (document == NULL) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
status = lxb_html_document_parse(document, data, length); | ||
if (status != LXB_STATUS_OK) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
lxb_html_document_destroy(document); | ||
|
||
return EXIT_SUCCESS; | ||
} |
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