summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/spectre_read_fuzzer.c49
-rw-r--r--test/spectre_read_fuzzer.cc46
2 files changed, 49 insertions, 46 deletions
diff --git a/test/spectre_read_fuzzer.c b/test/spectre_read_fuzzer.c
new file mode 100644
index 0000000..f121d93
--- /dev/null
+++ b/test/spectre_read_fuzzer.c
@@ -0,0 +1,49 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <inttypes.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "../libspectre/spectre.h"
+#include "../libspectre/spectre-utils.h"
+#include "../libspectre/ps.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ SpectreRenderContext *rc;
+ SpectreDocument *document;
+ char path[] = "/tmp/spectre_fuzz";
+
+ int fd = creat(path, 0644);
+
+ if(fd == -1) return 0;
+
+ write(fd, data, size);
+
+ close(fd);
+
+ document = spectre_document_new();
+ if(document == NULL) return 0;
+
+ spectre_document_load(document, path);
+
+ if(spectre_document_status(document))
+ {
+ spectre_document_free(document);
+ return 0;
+ }
+
+ spectre_document_free(document);
+
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/test/spectre_read_fuzzer.cc b/test/spectre_read_fuzzer.cc
deleted file mode 100644
index 2073f64..0000000
--- a/test/spectre_read_fuzzer.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stddef.h>
-#include <inttypes.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "../libspectre/spectre.h"
-#include "../libspectre/spectre-utils.h"
-#include "../libspectre/ps.h"
-
-int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
-{
- SpectreRenderContext *rc;
- SpectreDocument *document;
- unsigned int i;
-
- int fd = open("doc", O_CREAT | O_TMPFILE | O_TRUNC);
-
- if(fd == -1) return 0;
-
- while(write(fd, data, size) > 0);
-
- close(fd);
-
- spectre_document_load(document, "doc");
-
- if(spectre_document_status(document))
- {
- spectre_document_free(document);
- return 0;
- }
-
- spectre_document_free(document);
-
- return 0;
-}
-
-#ifdef __cplusplus
-}
-#endif \ No newline at end of file