From: Łukasz Stelmach Date: Tue, 9 Apr 2024 14:14:21 +0000 (+0200) Subject: tizen: Fix ln --relative X-Git-Tag: accepted/tizen/base/20240612.043335^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_base;p=product%2Fupstream%2Fcoreutils.git tizen: Fix ln --relative Include the a trailing slash when comparing directory names with strncmp(3). Add more thorough tests. Change-Id: I269988d1513db8b61f72be20ccad5ff1ca0f33ea Signed-off-by: Łukasz Stelmach --- diff --git a/src/ln.c b/src/ln.c index 97c3268..8db2047 100644 --- a/src/ln.c +++ b/src/ln.c @@ -274,7 +274,7 @@ do_link (const char *source, const char *dest) d = canon_dest = canonicalize_filename_mode(dest, CAN_ALL_BUT_LAST); if (!d) { - error(0, errno, "cannot canonicalize destination file name: %s", quote(source)); + error(0, errno, "cannot canonicalize destination file name: %s", quote(dest)); free(canon_source); return false; } @@ -292,7 +292,7 @@ do_link (const char *source, const char *dest) s++; d++; sp = strchr(s, '/'); dp = strchr(d, '/'); - while (strncmp(s, d, sp - s) == 0) + while (strncmp(s, d, sp - s + 1) == 0) { d = dp + 1; s = sp + 1; @@ -304,7 +304,7 @@ do_link (const char *source, const char *dest) memset(relative_source, 0, PATH_MAX); relative_len = 0; - while ((relative_len < (PATH_MAX - 1 - 3)) && (strncmp(d, dest_base, dp - d) != 0)) + while ((relative_len < (PATH_MAX - 1 - 3)) && (strncmp(d, dest_base, dp - d + 1) != 0)) { d = dp + 1; dp = strchr(d , '/'); diff --git a/tests/ln/relative b/tests/ln/relative index 4231531..e4ad462 100755 --- a/tests/ln/relative +++ b/tests/ln/relative @@ -29,10 +29,11 @@ trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' trap '(exit $?); exit $?' 1 2 13 15 framework_failure=0 -mkdir -p $tmp/a || framework_failure=1 -mkdir -p $tmp/z || framework_failure=1 -touch $tmp/b || framework_failure=1 -touch $tmp/a/b || framework_failure=1 +mkdir -p $tmp/A/B || framework_failure=1 +mkdir -p $tmp/Z/Y || framework_failure=1 +touch $tmp/a || framework_failure=1 +touch $tmp/A/b || framework_failure=1 +touch $tmp/A/B/c || framework_failure=1 cd $tmp || framework_failure=1 if test $framework_failure = 1; then @@ -42,16 +43,32 @@ fi fail=0 -ln -sr ./a/b ./y -test $(readlink y) = 'a/b' || fail=1 +ln -srT ./a ./x +test $(readlink x) = 'a' || fail=1 -ln -sr ./a/b ./z/y -test $(readlink z/y) = '../a/b' || fail=1 +ln -srT ./A/b ./y +test $(readlink y) = 'A/b' || fail=1 -ln -sr ./b ./z/x -test $(readlink z/x) = '../b' || fail=1 +ln -srT ./A/B/c ./z +test $(readlink z) = 'A/B/c' || fail=1 + +ln -srT ./a ./Z/x +test $(readlink Z/x) = '../a' || fail=1 + +ln -srT ./A/b ./Z/y +test $(readlink Z/y) = '../A/b' || fail=1 + +ln -srT ./A/B/c ./Z/z +test $(readlink Z/z) = '../A/B/c' || fail=1 + +ln -srT $(pwd)/a $(pwd)/Z/Y/x +test $(readlink Z/Y/x) = '../../a' || fail=1 + +ln -srT ./A/b ./Z/Y/Y +test $(readlink Z/Y/Y) = '../../A/b' || fail=1 + +ln -srT ./A/B/c ./Z/Y/z +test $(readlink Z/Y/z) = '../../A/B/c' || fail=1 -ln -sr ./b ./x -test $(readlink x) = 'b' || fail=1 (exit $fail); exit $fail