From e5fa4cdfb0469ed615d0f778b95b0755bfd7c9ca Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 25 Aug 2019 13:46:21 +0200 Subject: Add minimal test program for fuzzing the fstree_from_file parser Signed-off-by: David Oberhollenzer --- tests/Makemodule.am | 5 +++++ tests/fstree_fuzz.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/fstree_fuzz.c (limited to 'tests') diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 67f5642..f84852a 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -82,6 +82,9 @@ if HAVE_PTHREAD test_blk_proc_order_CPPFLAGS += -DHAVE_PTHREAD endif +fstree_fuzz_SOURCES = tests/fstree_fuzz.c +fstree_fuzz_LDADD = libfstree.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 @@ -91,6 +94,8 @@ 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 + TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file diff --git a/tests/fstree_fuzz.c b/tests/fstree_fuzz.c new file mode 100644 index 0000000..a9df1ab --- /dev/null +++ b/tests/fstree_fuzz.c @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fstree_fuzz.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" + +#include +#include + +int main(int argc, char **argv) +{ + int ret = EXIT_FAILURE; + fstree_t fs; + FILE *fp; + + if (argc != 2) { + fputs("Usage: fstree_fuzz \n", stderr); + return EXIT_FAILURE; + } + + fp = fopen(argv[1], "r"); + if (fp == NULL) { + perror(argv[1]); + return EXIT_FAILURE; + } + + if (fstree_init(&fs, 512, NULL)) + goto out_fp; + + if (fstree_from_file(&fs, argv[1], fp)) + goto out_fs; + + ret = EXIT_SUCCESS; +out_fs: + fstree_cleanup(&fs); +out_fp: + fclose(fp); + return ret; +} -- cgit v1.2.3