diff options
-rw-r--r-- | bin/rdsquashfs/describe.c | 2 | ||||
-rw-r--r-- | bin/rdsquashfs/fill_files.c | 2 | ||||
-rw-r--r-- | bin/rdsquashfs/restore_fstree.c | 4 | ||||
-rw-r--r-- | bin/sqfs2tar/write_tree.c | 2 | ||||
-rw-r--r-- | include/util/util.h | 6 | ||||
-rw-r--r-- | lib/common/hardlink.c | 2 | ||||
-rw-r--r-- | lib/util/filename_sane.c | 56 | ||||
-rw-r--r-- | tests/libutil/Makemodule.am | 7 | ||||
-rw-r--r-- | tests/libutil/filename_sane.c | 51 |
9 files changed, 11 insertions, 121 deletions
diff --git a/bin/rdsquashfs/describe.c b/bin/rdsquashfs/describe.c index 540b126..8c0fb16 100644 --- a/bin/rdsquashfs/describe.c +++ b/bin/rdsquashfs/describe.c @@ -76,7 +76,7 @@ int describe_tree(const sqfs_tree_node_t *root, const char *unpack_root) { const sqfs_tree_node_t *n; - if (!is_filename_sane((const char *)root->name, false)) { + if (!is_filename_sane((const char *)root->name)) { fprintf(stderr, "Encountered illegal file name '%s'\n", root->name); return -1; diff --git a/bin/rdsquashfs/fill_files.c b/bin/rdsquashfs/fill_files.c index 923bc12..660ef1b 100644 --- a/bin/rdsquashfs/fill_files.c +++ b/bin/rdsquashfs/fill_files.c @@ -115,7 +115,7 @@ static void clear_file_list(void) static int gen_file_list_dfs(const sqfs_tree_node_t *n) { - if (!is_filename_sane((const char *)n->name, true)) { + if (!is_filename_sane((const char *)n->name)) { fprintf(stderr, "Found an entry named '%s', skipping.\n", n->name); return 0; diff --git a/bin/rdsquashfs/restore_fstree.c b/bin/rdsquashfs/restore_fstree.c index ea9d4f1..bfe5d86 100644 --- a/bin/rdsquashfs/restore_fstree.c +++ b/bin/rdsquashfs/restore_fstree.c @@ -129,7 +129,7 @@ static int create_node_dfs(const sqfs_tree_node_t *n, int flags) char *name; int ret; - if (!is_filename_sane((const char *)n->name, true)) { + if (!is_filename_sane((const char *)n->name)) { fprintf(stderr, "Found an entry named '%s', skipping.\n", n->name); return 0; @@ -224,7 +224,7 @@ static int set_attribs(sqfs_xattr_reader_t *xattr, char *path; int ret; - if (!is_filename_sane((const char *)n->name, true)) + if (!is_filename_sane((const char *)n->name)) return 0; if (S_ISDIR(n->inode->base.mode)) { diff --git a/bin/sqfs2tar/write_tree.c b/bin/sqfs2tar/write_tree.c index 354ec21..48697a5 100644 --- a/bin/sqfs2tar/write_tree.c +++ b/bin/sqfs2tar/write_tree.c @@ -91,7 +91,7 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) name[len] = '/'; name[len + 1] = '\0'; } else { - if (!is_filename_sane((const char *)n->name, false)) { + if (!is_filename_sane((const char *)n->name)) { fprintf(stderr, "Found a file named '%s', skipping.\n", n->name); if (dont_skip) { diff --git a/include/util/util.h b/include/util/util.h index cd32887..db6a712 100644 --- a/include/util/util.h +++ b/include/util/util.h @@ -55,12 +55,8 @@ 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); +SQFS_INTERNAL bool is_filename_sane(const char *name); /* If the environment variable SOURCE_DATE_EPOCH is set to a parsable number diff --git a/lib/common/hardlink.c b/lib/common/hardlink.c index e43df33..41e068f 100644 --- a/lib/common/hardlink.c +++ b/lib/common/hardlink.c @@ -31,7 +31,7 @@ static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out, return 0; } - if (!is_filename_sane((const char *)n->name, false)) + if (!is_filename_sane((const char *)n->name)) return SQFS_ERROR_CORRUPTED; idx = n->inode->base.inode_number; diff --git a/lib/util/filename_sane.c b/lib/util/filename_sane.c index b52ce4d..f98aafc 100644 --- a/lib/util/filename_sane.c +++ b/lib/util/filename_sane.c @@ -9,68 +9,14 @@ #include <string.h> -#if defined(_WIN32) || defined(__WINDOWS__) || defined(TEST_WIN32) -#ifdef _MSC_VER -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif - -static const char *bad_names[] = { - "CON", "PRN", "AUX", "NUL", - "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", - "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", -}; - -static bool is_allowed_by_os(const char *name) -{ - size_t len, i; - - for (i = 0; i < sizeof(bad_names) / sizeof(bad_names[0]); ++i) { - len = strlen(bad_names[i]); - - if (strncasecmp(name, bad_names[i], len) != 0) - continue; - - if (name[len] == '\0') - return false; - - if (name[len] == '.' && strchr(name + len + 1, '.') == NULL) - return false; - } - - return true; -} -#else -static bool is_allowed_by_os(const char *name) -{ - (void)name; - return true; -} -#endif - -bool is_filename_sane(const char *name, bool check_os_specific) +bool is_filename_sane(const char *name) { if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) return false; - if (check_os_specific && !is_allowed_by_os(name)) - return false; - while (*name != '\0') { if (*name == '/') return false; - -#if defined(_WIN32) || defined(__WINDOWS__) || defined(TEST_WIN32) - if (check_os_specific) { - if (*name == '<' || *name == '>' || *name == ':') - return false; - if (*name == '"' || *name == '|' || *name == '?') - return false; - if (*name == '*' || *name == '\\' || *name <= 31) - return false; - } -#endif - ++name; } diff --git a/tests/libutil/Makemodule.am b/tests/libutil/Makemodule.am index c84f722..e039282 100644 --- a/tests/libutil/Makemodule.am +++ b/tests/libutil/Makemodule.am @@ -27,11 +27,6 @@ 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 - test_sdate_epoch_SOURCES = tests/libutil/epoch.c test_sdate_epoch_LDADD = libutil.a libcompat.a @@ -43,7 +38,7 @@ test_base64_decode_LDADD = libutil.a libcompat.a LIBUTIL_TESTS = \ test_str_table test_rbtree test_xxhash test_threadpool test_ismemzero \ - test_canonicalize_name test_filename_sane test_filename_sane_w32 \ + test_canonicalize_name test_filename_sane \ test_sdate_epoch test_hex_decode test_base64_decode check_PROGRAMS += $(LIBUTIL_TESTS) diff --git a/tests/libutil/filename_sane.c b/tests/libutil/filename_sane.c index 9c9930d..1a2cf72 100644 --- a/tests/libutil/filename_sane.c +++ b/tests/libutil/filename_sane.c @@ -11,9 +11,6 @@ static const char *must_work[] = { "foobar", "test.txt", -#if !defined(_WIN32) && !defined(__WINDOWS__) && !defined(TEST_WIN32) - "\\foo", "foo\\", "foo\\bar", -#endif NULL, }; @@ -26,68 +23,24 @@ static const char *must_not_work[] = { NULL, }; -static const char *must_not_work_here[] = { -#if defined(_WIN32) || defined(__WINDOWS__) || defined(TEST_WIN32) - "\\foo", "foo\\", "foo\\bar", - "fo<o", "fo>o", "fo:o", "fo\"o", - "fo|o", "fo?o", "fo*o", "fo\ro", - "CON", "PRN", "AUX", "NUL", - "COM1", "COM2", "LPT1", "LPT2", - "con", "prn", "aux", "nul", - "com1", "com2", "lpt1", "lpt2", - "AUX.txt", "aux.txt", "NUL.txt", "nul.txt", -#endif - NULL, -}; - int main(int argc, char **argv) { size_t i; (void)argc; (void)argv; for (i = 0; must_work[i] != NULL; ++i) { - if (!is_filename_sane(must_work[i], false)) { + if (!is_filename_sane(must_work[i])) { fprintf(stderr, "%s was rejected!\n", must_work[i]); return EXIT_FAILURE; } - - if (!is_filename_sane(must_work[i], true)) { - fprintf(stderr, - "%s was rejected when testing for " - "OS specific stuff!\n", must_work[i]); - return EXIT_FAILURE; - } } for (i = 0; must_not_work[i] != NULL; ++i) { - if (is_filename_sane(must_not_work[i], false)) { + if (is_filename_sane(must_not_work[i])) { fprintf(stderr, "%s was accepted!\n", must_not_work[i]); return EXIT_FAILURE; } - - if (is_filename_sane(must_not_work[i], true)) { - fprintf(stderr, - "%s was accepted when testing for " - "OS specific stuff!\n", must_not_work[i]); - return EXIT_FAILURE; - } - } - - for (i = 0; must_not_work_here[i] != NULL; ++i) { - if (!is_filename_sane(must_not_work_here[i], false)) { - fprintf(stderr, - "%s was rejected in the generic test!\n", - must_not_work_here[i]); - return EXIT_FAILURE; - } - - if (is_filename_sane(must_not_work_here[i], true)) { - fprintf(stderr, - "%s was accepted when testing for " - "OS specific stuff!\n", must_not_work_here[i]); - return EXIT_FAILURE; - } } return EXIT_SUCCESS; |