summaryrefslogtreecommitdiff
path: root/tests/tar_fuzz.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-26 09:19:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-26 09:20:31 +0200
commitc92a9513c9e21691b36868052c2d9489ab4be87b (patch)
treef80c41c0debc23e66a76cd56b940dcd6d4922381 /tests/tar_fuzz.c
parente5fa4cdfb0469ed615d0f778b95b0755bfd7c9ca (diff)
Move tar_fuzz program over to tests
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/tar_fuzz.c')
-rw-r--r--tests/tar_fuzz.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/tar_fuzz.c b/tests/tar_fuzz.c
new file mode 100644
index 0000000..4dc20f5
--- /dev/null
+++ b/tests/tar_fuzz.c
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * tar_fuzz.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "util.h"
+#include "tar.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+int main(int argc, char **argv)
+{
+ tar_header_decoded_t hdr;
+ int fd, ret;
+
+ if (argc != 2) {
+ fputs("usage: tar_fuzz <tarball>\n", stderr);
+ return EXIT_FAILURE;
+ }
+
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ perror(argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ for (;;) {
+ ret = read_header(fd, &hdr);
+ if (ret > 0)
+ break;
+ if (ret < 0)
+ goto fail;
+
+ ret = lseek(fd, hdr.sb.st_size, SEEK_CUR);
+
+ clear_header(&hdr);
+ if (ret)
+ goto fail;
+ }
+
+ close(fd);
+ return EXIT_SUCCESS;
+fail:
+ close(fd);
+ return EXIT_FAILURE;
+}