summaryrefslogtreecommitdiff
path: root/test/spectre_read_fuzzer.c
diff options
context:
space:
mode:
authorRandy <randy408@protonmail.com>2020-03-10 21:34:26 +0000
committerAlbert Astals Cid <tsdgeos@yahoo.es>2020-03-10 21:34:26 +0000
commita6329a26cbc8a920cf56531a762bfbf62b3ddc9d (patch)
treebe56164498c82df74987b6b5334f67f233739282 /test/spectre_read_fuzzer.c
parent567f72a04dcc5e883e708bd2a3a149e818c1c12f (diff)
Refactor spectre_document_load_from_data() -> _stream()
Diffstat (limited to 'test/spectre_read_fuzzer.c')
-rw-r--r--test/spectre_read_fuzzer.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/spectre_read_fuzzer.c b/test/spectre_read_fuzzer.c
index a0ca3e6..4a0601a 100644
--- a/test/spectre_read_fuzzer.c
+++ b/test/spectre_read_fuzzer.c
@@ -18,20 +18,33 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
+ FILE *f;
SpectreDocument *document;
+/* This is part of the build, it should at least compile on Windows */
+#if _POSIX_C_SOURCE >= 200809L
+ f = fmemopen((void*)data, size, "rb");
+ if(f == NULL) return 0;
+#endif
+
document = spectre_document_new();
- if(document == NULL) return 0;
+ if(document == NULL)
+ {
+ fclose(f);
+ return 0;
+ }
- spectre_document_load_from_data(document, (void*)data, size);
+ spectre_document_load_from_stream(document, f);
if(spectre_document_status(document))
{
spectre_document_free(document);
+ fclose(f);
return 0;
}
spectre_document_free(document);
+ fclose(f);
return 0;
}