unsafe-byname.test 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #! /bin/sh
  2. # Copyright (C) 2002 by Martin Pool
  3. # Call directly into unsafe_symlink and test its handling of various filenames
  4. . "$suitedir/rsync.fns"
  5. test_unsafe() {
  6. # $1 is the target of a symlink
  7. # $2 is the directory we're copying
  8. # $3 is the expected outcome: "safe" if the link lies within $2,
  9. # or "unsafe" otherwise
  10. result=`"$TOOLDIR/t_unsafe" "$1" "$2"` || test_fail "Failed to check $1 $2"
  11. if [ "$result" != "$3" ]
  12. then
  13. test_fail "t_unsafe $1 $2 returned \"$result\", expected \"$3\""
  14. fi
  15. }
  16. test_unsafe file from safe
  17. test_unsafe dir/file from safe
  18. test_unsafe dir/./file from safe
  19. test_unsafe dir/. from safe
  20. test_unsafe dir/ from safe
  21. test_unsafe /etc/passwd from unsafe
  22. test_unsafe //../etc/passwd from unsafe
  23. test_unsafe //./etc/passwd from unsafe
  24. test_unsafe ./foo from safe
  25. test_unsafe ../foo from unsafe
  26. test_unsafe ./../foo from unsafe
  27. test_unsafe .//../foo from unsafe
  28. test_unsafe ./../foo from/.. unsafe
  29. test_unsafe ../dest from/dir safe
  30. test_unsafe ../../dest from//dir unsafe
  31. test_unsafe ..//../dest from/dir unsafe
  32. test_unsafe .. from/file safe
  33. test_unsafe ../.. from/file unsafe
  34. test_unsafe ..//.. from//file unsafe
  35. test_unsafe dir/.. from safe
  36. test_unsafe dir/../.. from unsafe
  37. test_unsafe dir/..//.. from unsafe
  38. test_unsafe '' from unsafe
  39. # Based on tests from unsafe-links by Vladimír Michl
  40. test_unsafe ../../unsafe/unsafefile from/safe unsafe
  41. test_unsafe ..//../unsafe/unsafefile from/safe unsafe
  42. test_unsafe ../files/file1 from/safe safe
  43. test_unsafe ../../unsafe/unsafefile safe unsafe
  44. test_unsafe ../files/file1 safe unsafe
  45. test_unsafe ../../unsafe/unsafefile `pwd`/from/safe safe
  46. test_unsafe ../files/file1 `pwd`/from/safe safe