inotify-hash-abuse.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. # Exercise an abort-inducing flaw in inotify-enabled tail -F.
  3. # Copyright (C) 2009-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ tail
  16. # 9 is a magic number, related to internal details of tail.c and hash.c
  17. n=9
  18. seq $n | xargs touch || framework_failure_
  19. check_tail_output()
  20. {
  21. local delay="$1"
  22. grep "$tail_re" out > /dev/null ||
  23. { sleep $delay; return 1; }
  24. }
  25. # Terminate any background tail process
  26. cleanup_() { kill $pid 2>/dev/null && wait $pid; }
  27. # Speedup the non inotify case
  28. fastpoll='-s.1 --max-unchanged-stats=1'
  29. for mode in '' '---disable-inotify'; do
  30. rm -f out
  31. tail $mode $fastpoll -qF $(seq $n) > out 2>&1 & pid=$!
  32. # Wait up to 12.7s for tail to start
  33. echo x > $n
  34. tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
  35. { cat out; fail=1; }
  36. mv 1 f || framework_failure_
  37. # Wait 12.7s for this diagnostic:
  38. # tail: '1' has become inaccessible: No such file or directory
  39. tail_re='inaccessible' retry_delay_ check_tail_output .1 7 ||
  40. { cat out; fail=1; }
  41. # Trigger the bug. Before the fix, this would provoke the abort.
  42. echo a > 1 || framework_failure_
  43. # Wait up to 6.3s for the "tail: '1' has appeared; ..." message
  44. # (or for the buggy tail to die)
  45. tail_re='has appeared' retry_delay_ check_tail_output .1 6 ||
  46. { cat out; fail=1; }
  47. # Double check that tail hasn't aborted
  48. kill -0 $pid || fail=1
  49. cleanup_
  50. done
  51. Exit $fail