From 42bea2b72b28cdd4f3666595b2252ee117c4ae33 Mon Sep 17 00:00:00 2001 From: arai Date: Sun, 2 Mar 2008 10:21:41 +0000 Subject: [PATCH] should remove duplicated slash git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@884 6a8cc165-1e22-0410-a132-eb4e3f353aba --- ChangeLog | 7 +++++++ configure.ac | 2 +- src/header.c | 15 ++++++++++++--- tests/lha-test17 | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8ef739..dd625bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-02-21 Koji Arai + + * src/header.c (canon_path): should remove duplicated slash. + (the function name is renamed from remove_dots().) + + * tests/lha-test17: added a test for above. + 2008-02-17 Koji Arai * src/lhext.c (extract_one) could not extract files under readonly directories, like: diff --git a/configure.ac b/configure.ac index ae6bddd..810bf2a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([LHa for UNIX], 1.14i-ac20080217, arai@users.sourceforge.jp, lha) +AC_INIT([LHa for UNIX], 1.14i-ac20080221, arai@users.sourceforge.jp, lha) AC_DEFINE_UNQUOTED(LHA_CONFIGURE_OPTIONS, "$ac_configure_args", [specified options for the configure script.]) AC_CANONICAL_HOST diff --git a/src/header.c b/src/header.c index ccd7918..fa544f3 100644 --- a/src/header.c +++ b/src/header.c @@ -1327,9 +1327,15 @@ copy_path_element(char *dst, const char *src, int size) return i; } -/* remove leading "xxx/../" and "./" */ +/* + canonicalize path + + remove leading "xxx/../" + remove "./", "././", "././ ... ./" + remove duplicated "/" +*/ static int -remove_dots(char *newpath, char *path, size_t size) +canon_path(char *newpath, char *path, size_t size) { int len; char *p = newpath; @@ -1349,6 +1355,9 @@ remove_dots(char *newpath, char *path, size_t size) if (size <= 1) break; } + + /* remove duplicated '/' */ + while (*path == '/') path++; } /* When newpath is empty, set "." */ @@ -1379,7 +1388,7 @@ init_header(name, v_stat, hdr) hdr->attribute = GENERIC_ATTRIBUTE; hdr->header_level = header_level; - len = remove_dots(hdr->name, name, sizeof(hdr->name)); + len = canon_path(hdr->name, name, sizeof(hdr->name)); hdr->crc = 0x0000; hdr->extend_type = EXTEND_UNIX; diff --git a/tests/lha-test17 b/tests/lha-test17 index 06338ef..9e51d7b 100644 --- a/tests/lha-test17 +++ b/tests/lha-test17 @@ -166,3 +166,27 @@ EOF egrep -v -- '-lh' test-tmp-stdout | diff - test-tmp-expect check $? $LINENO echo ------------------------------------------------------------------- +# remove duplicated slash "xxx//xxx" -> "xxx/xxx" +(cd test-1 && + $lha c $builddir/test-tmp-10.lzh ./test-a .//test-b .///test-c + ) + check $? $LINENO +$lha a test-tmp-10.lzh ./test-1/test-a .//test-1//test-b .///test-1///test-c + +$lha vvq test-tmp-10.lzh +$lha vvq test-tmp-10.lzh > test-tmp-stdout + check $? $LINENO +# followings is sorted by argument strings. +# XXX: this behavior is undesirable. +cat <<"EOF" > test-tmp-expect +test-1/test-c +test-1/test-b +test-1/test-a +test-c +test-b +test-a +EOF + +egrep -v -- '-lh' test-tmp-stdout | diff - test-tmp-expect + check $? $LINENO +echo ------------------------------------------------------------------- -- 2.11.0