fuzz-mdhtml.c: Cleanup of the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/test/fuzzers/fuzz-mdhtml.c b/test/fuzzers/fuzz-mdhtml.c
index 62428c8..2d645d2 100644
--- a/test/fuzzers/fuzz-mdhtml.c
+++ b/test/fuzzers/fuzz-mdhtml.c
@@ -1,28 +1,35 @@
+
#include <stdint.h>
#include <stdlib.h>
#include "md4c-html.h"
+
static void
process_output(const MD_CHAR* text, MD_SIZE size, void* userdata)
{
- /* This is dummy function because we dont need any processing on the data */
+ /* This is a dummy function because we don't need to generate any output
+ * actually. */
return;
}
-int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){
- if (size < 8) {
+int
+LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ unsigned parser_flags, renderer_flags;
+
+ if(size < 2 * sizeof(unsigned)) {
+ /* We interpret the 1st 8 bytes as parser flags and renderer flags. */
return 0;
}
- unsigned int parser_flags = *(unsigned int*)data;
- data += 4; size -= 4;
- unsigned int renderer_flags = *(unsigned int*)data;
- data += 4; size -= 4;
+ parser_flags = *(unsigned*)data;
+ data += sizeof(unsigned); size -= sizeof(unsigned);
+
+ renderer_flags = *(unsigned*)data;
+ data += sizeof(unsigned); size -= sizeof(unsigned);
/* Allocate enough space */
- char *out = malloc(size*3);
- md_html(data, size, process_output, out, parser_flags, renderer_flags);
- free(out);
+ md_html(data, size, process_output, NULL, parser_flags, renderer_flags);
return 0;
}