From c92a9513c9e21691b36868052c2d9489ab4be87b Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 26 Aug 2019 09:19:28 +0200 Subject: Move tar_fuzz program over to tests Signed-off-by: David Oberhollenzer --- tar/Makemodule.am | 4 ---- tar/tar_fuzz.c | 52 ---------------------------------------------------- tests/Makemodule.am | 5 ++++- tests/tar_fuzz.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 57 deletions(-) delete mode 100644 tar/tar_fuzz.c create mode 100644 tests/tar_fuzz.c diff --git a/tar/Makemodule.am b/tar/Makemodule.am index 551f4cd..b8674c2 100644 --- a/tar/Makemodule.am +++ b/tar/Makemodule.am @@ -8,8 +8,4 @@ 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 deleted file mode 100644 index 4dc20f5..0000000 --- a/tar/tar_fuzz.c +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_fuzz.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "util.h" -#include "tar.h" - -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - tar_header_decoded_t hdr; - int fd, ret; - - if (argc != 2) { - fputs("usage: tar_fuzz \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; -} diff --git a/tests/Makemodule.am b/tests/Makemodule.am index f84852a..c6ba1d9 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -85,6 +85,9 @@ endif fstree_fuzz_SOURCES = tests/fstree_fuzz.c fstree_fuzz_LDADD = libfstree.a libutil.a +tar_fuzz_SOURCES = tests/tar_fuzz.c +tar_fuzz_LDADD = libtar.a libutil.a + check_PROGRAMS += test_canonicalize_name test_mknode_simple test_mknode_slink check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table check_PROGRAMS += test_add_by_path test_get_path test_fstree_sort @@ -94,7 +97,7 @@ check_PROGRAMS += test_tar_sparse_gnu1 test_tar_sparse_gnu2 check_PROGRAMS += test_tar_xattr_bsd test_tar_xattr_schily test_str_table check_PROGRAMS += test_blk_proc_order -noinst_PROGRAMS += fstree_fuzz +noinst_PROGRAMS += fstree_fuzz tar_fuzz TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table 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 + */ +#include "config.h" + +#include "util.h" +#include "tar.h" + +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + int fd, ret; + + if (argc != 2) { + fputs("usage: tar_fuzz \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; +} -- cgit v1.2.3