summaryrefslogtreecommitdiffstats
path: root/tests/fuzz-main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 21:41:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 21:41:43 +0000
commit92cccad89d1c12b39165d5f0ed7ccd2d44965a1a (patch)
treef59a2764cd8c50959050a428bd8fc935138df750 /tests/fuzz-main.c
parentInitial commit. (diff)
downloadlibtpms-92cccad89d1c12b39165d5f0ed7ccd2d44965a1a.tar.xz
libtpms-92cccad89d1c12b39165d5f0ed7ccd2d44965a1a.zip
Adding upstream version 0.9.2.upstream/0.9.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/fuzz-main.c')
-rw-r--r--tests/fuzz-main.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/fuzz-main.c b/tests/fuzz-main.c
new file mode 100644
index 0000000..95634a0
--- /dev/null
+++ b/tests/fuzz-main.c
@@ -0,0 +1,50 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#define MIN_NUMBER_OF_RUNS 4
+#define EXIT_TEST_SKIP 77
+
+extern int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size);
+
+int main(int argc, char **argv)
+{
+ int i, j;
+
+ for (i = 1; i < argc; i++) {
+ char *name = argv[i];
+ ssize_t size;
+ FILE *f = fopen(name, "rb");
+ char *buf;
+
+ fprintf(stdout, "%s...\n", name);
+ if (f == NULL) {
+ perror("fopen() failed");
+ continue;
+ }
+ fseek(f, 0, SEEK_END);
+ size = ftell(f);
+ if (size < 0) {
+ fclose(f);
+ perror("ftell() failed");
+ continue;
+ }
+ fseek(f, 0, SEEK_SET);
+ buf = malloc(size + 1);
+ if (fread(buf, 1, size, f) != (size_t)size) {
+ fclose(f);
+ perror("fread() failed");
+ continue;
+ }
+ fclose(f);
+ buf[size] = 0;
+
+ for (j = 0; j < MIN_NUMBER_OF_RUNS; j++) {
+ if (LLVMFuzzerTestOneInput((void *)buf, size) == EXIT_TEST_SKIP) {
+ return EXIT_TEST_SKIP;
+ }
+ }
+ free(buf);
+ }
+
+ return EXIT_SUCCESS;
+}