diff options
-rw-r--r-- | bin/gensquashfs/Makemodule.am | 2 | ||||
-rw-r--r-- | bin/gensquashfs/mkfs.h | 1 | ||||
-rw-r--r-- | bin/sqfs2tar/sqfs2tar.h | 3 | ||||
-rw-r--r-- | bin/tar2sqfs/Makemodule.am | 2 | ||||
-rw-r--r-- | bin/tar2sqfs/tar2sqfs.h | 1 | ||||
-rw-r--r-- | include/fstree.h | 19 | ||||
-rw-r--r-- | include/util/util.h | 19 | ||||
-rw-r--r-- | lib/common/hardlink.c | 1 | ||||
-rw-r--r-- | lib/fstree/Makemodule.am | 2 | ||||
-rw-r--r-- | lib/fstree/fstree_from_file.c | 1 | ||||
-rw-r--r-- | lib/fstree/hardlink.c | 1 | ||||
-rw-r--r-- | lib/fstree/sort_by_file.c | 1 | ||||
-rw-r--r-- | lib/util/Makemodule.am | 2 | ||||
-rw-r--r-- | lib/util/canonicalize_name.c (renamed from lib/fstree/canonicalize_name.c) | 4 | ||||
-rw-r--r-- | lib/util/filename_sane.c (renamed from lib/fstree/filename_sane.c) | 4 | ||||
-rw-r--r-- | tests/libfstree/Makemodule.am | 28 | ||||
-rw-r--r-- | tests/libfstree/sort_file.c | 1 | ||||
-rw-r--r-- | tests/libutil/Makemodule.am | 15 | ||||
-rw-r--r-- | tests/libutil/canonicalize_name.c (renamed from tests/libfstree/canonicalize_name.c) | 2 | ||||
-rw-r--r-- | tests/libutil/filename_sane.c (renamed from tests/libfstree/filename_sane.c) | 2 |
20 files changed, 60 insertions, 51 deletions
diff --git a/bin/gensquashfs/Makemodule.am b/bin/gensquashfs/Makemodule.am index 03f4f4c..b0b8a79 100644 --- a/bin/gensquashfs/Makemodule.am +++ b/bin/gensquashfs/Makemodule.am @@ -2,7 +2,7 @@ gensquashfs_SOURCES = bin/gensquashfs/mkfs.c bin/gensquashfs/mkfs.h gensquashfs_SOURCES += bin/gensquashfs/options.c bin/gensquashfs/selinux.c gensquashfs_SOURCES += bin/gensquashfs/dirscan_xattr.c gensquashfs_LDADD = libcommon.a libsquashfs.la libfstree.a libio.a -gensquashfs_LDADD += libcompat.a $(LZO_LIBS) $(PTHREAD_LIBS) +gensquashfs_LDADD += libutil.a libcompat.a $(LZO_LIBS) $(PTHREAD_LIBS) gensquashfs_CPPFLAGS = $(AM_CPPFLAGS) gensquashfs_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) diff --git a/bin/gensquashfs/mkfs.h b/bin/gensquashfs/mkfs.h index 4f455bd..2697d3e 100644 --- a/bin/gensquashfs/mkfs.h +++ b/bin/gensquashfs/mkfs.h @@ -11,6 +11,7 @@ #include "common.h" #include "fstree.h" +#include "util/util.h" #ifdef HAVE_SYS_XATTR_H #include <sys/xattr.h> diff --git a/bin/sqfs2tar/sqfs2tar.h b/bin/sqfs2tar/sqfs2tar.h index 4575793..71b491d 100644 --- a/bin/sqfs2tar/sqfs2tar.h +++ b/bin/sqfs2tar/sqfs2tar.h @@ -9,8 +9,9 @@ #include "config.h" #include "common.h" -#include "tar/tar.h" +#include "util/util.h" +#include "tar/tar.h" #include "io/xfrm.h" #include <getopt.h> diff --git a/bin/tar2sqfs/Makemodule.am b/bin/tar2sqfs/Makemodule.am index 818f6e2..a9c503f 100644 --- a/bin/tar2sqfs/Makemodule.am +++ b/bin/tar2sqfs/Makemodule.am @@ -2,7 +2,7 @@ tar2sqfs_SOURCES = bin/tar2sqfs/tar2sqfs.c bin/tar2sqfs/tar2sqfs.h tar2sqfs_SOURCES += bin/tar2sqfs/options.c bin/tar2sqfs/process_tarball.c tar2sqfs_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) tar2sqfs_LDADD = libcommon.a libsquashfs.la libtar.a libio.a -tar2sqfs_LDADD += libfstree.a libcompat.a libfstree.a $(LZO_LIBS) +tar2sqfs_LDADD += libfstree.a libcompat.a libfstree.a libutil.a $(LZO_LIBS) tar2sqfs_LDADD += $(ZLIB_LIBS) $(XZ_LIBS) $(ZSTD_LIBS) $(BZIP2_LIBS) tar2sqfs_LDADD += $(PTHREAD_LIBS) diff --git a/bin/tar2sqfs/tar2sqfs.h b/bin/tar2sqfs/tar2sqfs.h index 40c3b75..6e4d123 100644 --- a/bin/tar2sqfs/tar2sqfs.h +++ b/bin/tar2sqfs/tar2sqfs.h @@ -11,6 +11,7 @@ #include "common.h" #include "compat.h" +#include "util/util.h" #include "tar/tar.h" #include "tar/format.h" #include "io/xfrm.h" diff --git a/include/fstree.h b/include/fstree.h index 3fb4f47..7bdbddf 100644 --- a/include/fstree.h +++ b/include/fstree.h @@ -237,25 +237,6 @@ tree_node_t *fstree_get_node_by_path(fstree_t *fs, tree_node_t *root, bool stop_at_parent); /* - Convert back to forward slashed, remove all preceeding and trailing slashes, - collapse all sequences of slashes, remove all path components that are '.' - and returns failure state if one of the path components is '..'. - - Returns 0 on success. -*/ -int canonicalize_name(char *filename); - -/* - Returns true if a given filename is sane, false if it is not (e.g. contains - slashes or it is equal to '.' or '..'). - - If check_os_specific is true, this also checks if the filename contains - a character, or is equal to a name, that is black listed on the current OS. - E.g. on Windows, a file named "COM0" or "AUX" is a no-no. - */ -bool is_filename_sane(const char *name, bool check_os_specific); - -/* Add a hard link node. Returns NULL on failure and sets errno. */ tree_node_t *fstree_add_hard_link(fstree_t *fs, const char *path, diff --git a/include/util/util.h b/include/util/util.h index af7d196..c18a558 100644 --- a/include/util/util.h +++ b/include/util/util.h @@ -43,4 +43,23 @@ SQFS_INTERNAL bool is_memory_zero(const void *blob, size_t size); */ SQFS_INTERNAL int mkdir_p(const char *path); +/* + Remove all preceeding and trailing slashes, collapse all sequences of + slashes, remove all path components that are '.' and returns failure + state if one of the path components is '..'. + + Returns 0 on success. +*/ +SQFS_INTERNAL int canonicalize_name(char *filename); + +/* + Returns true if a given filename is sane, false if it is not (e.g. contains + slashes or it is equal to '.' or '..'). + + If check_os_specific is true, this also checks if the filename contains + a character, or is equal to a name, that is black listed on the current OS. + E.g. on Windows, a file named "COM0" or "AUX" is a no-no. + */ +SQFS_INTERNAL bool is_filename_sane(const char *name, bool check_os_specific); + #endif /* SQFS_UTIL_H */ diff --git a/lib/common/hardlink.c b/lib/common/hardlink.c index f8d4d4a..f28620f 100644 --- a/lib/common/hardlink.c +++ b/lib/common/hardlink.c @@ -6,6 +6,7 @@ */ #include "common.h" #include "util/rbtree.h" +#include "util/util.h" #include <stdlib.h> #include <assert.h> diff --git a/lib/fstree/Makemodule.am b/lib/fstree/Makemodule.am index c2981ce..fec63b4 100644 --- a/lib/fstree/Makemodule.am +++ b/lib/fstree/Makemodule.am @@ -5,8 +5,6 @@ libfstree_a_SOURCES += lib/fstree/mknode.c lib/fstree/fstree_from_dir.c libfstree_a_SOURCES += lib/fstree/add_by_path.c lib/fstree/get_by_path.c libfstree_a_SOURCES += include/fstree.h lib/fstree/internal.h libfstree_a_SOURCES += lib/fstree/source_date_epoch.c -libfstree_a_SOURCES += lib/fstree/canonicalize_name.c -libfstree_a_SOURCES += lib/fstree/filename_sane.c libfstree_a_SOURCES += lib/fstree/sort_by_file.c libfstree_a_CFLAGS = $(AM_CFLAGS) libfstree_a_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c index dd289bc..411c64f 100644 --- a/lib/fstree/fstree_from_file.c +++ b/lib/fstree/fstree_from_file.c @@ -6,6 +6,7 @@ */ #include "config.h" +#include "util/util.h" #include "io/file.h" #include "fstree.h" #include "compat.h" diff --git a/lib/fstree/hardlink.c b/lib/fstree/hardlink.c index f45acf7..2165b5f 100644 --- a/lib/fstree/hardlink.c +++ b/lib/fstree/hardlink.c @@ -6,6 +6,7 @@ */ #include "config.h" +#include "util/util.h" #include "fstree.h" #include <string.h> diff --git a/lib/fstree/sort_by_file.c b/lib/fstree/sort_by_file.c index 7f1f19f..ed4a58c 100644 --- a/lib/fstree/sort_by_file.c +++ b/lib/fstree/sort_by_file.c @@ -6,6 +6,7 @@ */ #include "config.h" +#include "util/util.h" #include "fstree.h" #include "compat.h" diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am index bc3d618..d37f2b1 100644 --- a/lib/util/Makemodule.am +++ b/lib/util/Makemodule.am @@ -10,6 +10,8 @@ libutil_a_SOURCES += include/util/w32threadwrap.h libutil_a_SOURCES += lib/util/threadpool_serial.c libutil_a_SOURCES += lib/util/is_memory_zero.c libutil_a_SOURCES += lib/util/mkdir_p.c +libutil_a_SOURCES += lib/util/canonicalize_name.c +libutil_a_SOURCES += lib/util/filename_sane.c libutil_a_CFLAGS = $(AM_CFLAGS) libutil_a_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/lib/fstree/canonicalize_name.c b/lib/util/canonicalize_name.c index 7fbd5a7..534e89e 100644 --- a/lib/fstree/canonicalize_name.c +++ b/lib/util/canonicalize_name.c @@ -1,11 +1,11 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ /* * canonicalize_name.c * * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> */ #include "config.h" -#include "fstree.h" +#include "util/util.h" static void normalize_slashes(char *filename) { diff --git a/lib/fstree/filename_sane.c b/lib/util/filename_sane.c index 91c15da..b52ce4d 100644 --- a/lib/fstree/filename_sane.c +++ b/lib/util/filename_sane.c @@ -1,11 +1,11 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ /* * filename_sane.c * * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> */ #include "config.h" -#include "fstree.h" +#include "util/util.h" #include <string.h> diff --git a/tests/libfstree/Makemodule.am b/tests/libfstree/Makemodule.am index a79d670..107a66c 100644 --- a/tests/libfstree/Makemodule.am +++ b/tests/libfstree/Makemodule.am @@ -1,8 +1,5 @@ FSTDATADIR=$(top_srcdir)/tests/libfstree -test_canonicalize_name_SOURCES = tests/libfstree/canonicalize_name.c -test_canonicalize_name_LDADD = libfstree.a libcompat.a - test_mknode_simple_SOURCES = tests/libfstree/mknode_simple.c test_mknode_simple_LDADD = libfstree.a libcompat.a @@ -16,7 +13,7 @@ test_mknode_dir_SOURCES = tests/libfstree/mknode_dir.c test_mknode_dir_LDADD = libfstree.a libcompat.a test_gen_inode_numbers_SOURCES = tests/libfstree/gen_inode_numbers.c -test_gen_inode_numbers_LDADD = libfstree.a libcompat.a +test_gen_inode_numbers_LDADD = libfstree.a libutil.a libcompat.a test_add_by_path_SOURCES = tests/libfstree/add_by_path.c test_add_by_path_LDADD = libfstree.a libcompat.a @@ -31,46 +28,37 @@ test_fstree_sort_LDADD = libfstree.a libio.a libcompat.a test_fstree_from_file_SOURCES = tests/libfstree/fstree_from_file.c test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) test_fstree_from_file_CPPFLAGS += -DTESTPATH=$(FSTDATADIR)/fstree1.txt -test_fstree_from_file_LDADD = libfstree.a libio.a libcompat.a +test_fstree_from_file_LDADD = libfstree.a libio.a libutil.a libcompat.a test_fstree_glob1_SOURCES = tests/libfstree/fstree_glob1.c test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(FSTDATADIR) -test_fstree_glob1_LDADD = libfstree.a libio.a libcompat.a +test_fstree_glob1_LDADD = libfstree.a libio.a libutil.a libcompat.a test_fstree_from_dir_SOURCES = tests/libfstree/fstree_from_dir.c test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS) test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/libtar/data -test_fstree_from_dir_LDADD = libfstree.a libcompat.a +test_fstree_from_dir_LDADD = libfstree.a libutil.a libcompat.a test_fstree_init_SOURCES = tests/libfstree/fstree_init.c test_fstree_init_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree test_fstree_init_LDADD = libfstree.a libio.a libcompat.a -test_filename_sane_SOURCES = tests/libfstree/filename_sane.c -test_filename_sane_SOURCES += lib/fstree/filename_sane.c -test_filename_sane_LDADD = libcompat.a - -test_filename_sane_w32_SOURCES = tests/libfstree/filename_sane.c -test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c -test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1 -test_filename_sane_w32_LDADD = libcompat.a - test_fstree_epoch_SOURCES = tests/libfstree/epoch.c test_fstree_epoch_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree test_fstree_epoch_SOURCES += lib/fstree/source_date_epoch.c test_fstree_epoch_LDADD = libcompat.a test_sort_file_SOURCES = tests/libfstree/sort_file.c -test_sort_file_LDADD = libfstree.a libio.a libcompat.a +test_sort_file_LDADD = libfstree.a libio.a libutil.a libcompat.a fstree_fuzz_SOURCES = tests/libfstree/fstree_fuzz.c -fstree_fuzz_LDADD = libfstree.a libio.a libcompat.a +fstree_fuzz_LDADD = libfstree.a libio.a libutil.a libcompat.a FSTREE_TESTS = \ - test_canonicalize_name test_mknode_simple test_mknode_slink \ + test_mknode_simple test_mknode_slink \ test_mknode_reg test_mknode_dir test_gen_inode_numbers \ test_add_by_path test_get_path test_fstree_sort test_fstree_from_file \ - test_fstree_init test_filename_sane test_filename_sane_w32 \ + test_fstree_init \ test_fstree_from_dir test_fstree_glob1 test_fstree_epoch \ test_sort_file diff --git a/tests/libfstree/sort_file.c b/tests/libfstree/sort_file.c index 93d60e0..78d1606 100644 --- a/tests/libfstree/sort_file.c +++ b/tests/libfstree/sort_file.c @@ -9,6 +9,7 @@ #include "sqfs/block.h" #include "fstree.h" #include "util/test.h" +#include "util/util.h" static const char *listing = "dir /bin 0755 0 0\n" diff --git a/tests/libutil/Makemodule.am b/tests/libutil/Makemodule.am index 95fb8ab..a3853d2 100644 --- a/tests/libutil/Makemodule.am +++ b/tests/libutil/Makemodule.am @@ -15,8 +15,21 @@ test_threadpool_LDADD = libutil.a libcompat.a $(PTHREAD_LIBS) test_ismemzero_SOURCES = tests/libutil/is_memory_zero.c test_ismemzero_LDADD = libutil.a libcompat.a +test_canonicalize_name_SOURCES = tests/libutil/canonicalize_name.c +test_canonicalize_name_LDADD = libutil.a libcompat.a + +test_filename_sane_SOURCES = tests/libutil/filename_sane.c +test_filename_sane_SOURCES += lib/util/filename_sane.c +test_filename_sane_LDADD = libcompat.a libutil.a + +test_filename_sane_w32_SOURCES = tests/libutil/filename_sane.c +test_filename_sane_w32_SOURCES += lib/util/filename_sane.c +test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1 +test_filename_sane_w32_LDADD = libcompat.a + LIBUTIL_TESTS = \ - test_str_table test_rbtree test_xxhash test_threadpool test_ismemzero + test_str_table test_rbtree test_xxhash test_threadpool test_ismemzero \ + test_canonicalize_name test_filename_sane test_filename_sane_w32 check_PROGRAMS += $(LIBUTIL_TESTS) TESTS += $(LIBUTIL_TESTS) diff --git a/tests/libfstree/canonicalize_name.c b/tests/libutil/canonicalize_name.c index f117a0d..9f81b04 100644 --- a/tests/libfstree/canonicalize_name.c +++ b/tests/libutil/canonicalize_name.c @@ -5,7 +5,7 @@ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> */ #include "config.h" -#include "fstree.h" +#include "util/util.h" #include "util/test.h" static const struct { diff --git a/tests/libfstree/filename_sane.c b/tests/libutil/filename_sane.c index a1dc79c..9c9930d 100644 --- a/tests/libfstree/filename_sane.c +++ b/tests/libutil/filename_sane.c @@ -5,7 +5,7 @@ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> */ #include "config.h" -#include "fstree.h" +#include "util/util.h" #include "util/test.h" static const char *must_work[] = { |