diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-24 21:26:44 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-24 21:27:13 +0200 |
commit | 2d43d376d38ebf91d0ef6b8711bdc134aa1abdd6 (patch) | |
tree | f18c25ca41e210ff34a04a67a1f25970d50a7f11 | |
parent | e31c0fcd809a649b70e6bab08a8b89f9ced07510 (diff) |
Add minimal test program for fuzzing the tar parser
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | tar/Makemodule.am | 4 | ||||
-rw-r--r-- | tar/tar_fuzz.c | 52 |
3 files changed, 57 insertions, 0 deletions
@@ -23,6 +23,7 @@ rdsquashfs sqfs2tar tar2sqfs sqfsdiff +tar_fuzz test_* test-* fscompare diff --git a/tar/Makemodule.am b/tar/Makemodule.am index b8674c2..551f4cd 100644 --- a/tar/Makemodule.am +++ b/tar/Makemodule.am @@ -8,4 +8,8 @@ tar2sqfs_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) tar2sqfs_LDADD += $(XZ_LIBS) $(ZLIB_LIBS) $(LZO_LIBS) $(LZ4_LIBS) $(ZSTD_LIBS) tar2sqfs_LDADD += $(PTHREAD_LIBS) +tar_fuzz_SOURCES = tar/tar_fuzz.c +tar_fuzz_LDADD = libtar.a libutil.a + bin_PROGRAMS += sqfs2tar tar2sqfs +noinst_PROGRAMS += tar_fuzz diff --git a/tar/tar_fuzz.c b/tar/tar_fuzz.c new file mode 100644 index 0000000..4dc20f5 --- /dev/null +++ b/tar/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; +} |