run_stringtests 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. SYSCTL="/proc/sys"
  3. TARGET="${SYSCTL}/kernel/domainname"
  4. ORIG=$(cat "${TARGET}")
  5. TEST_STR="Testing sysctl"
  6. . ./common_tests
  7. # Only string sysctls support seeking/appending.
  8. MAXLEN=65
  9. echo -n "Writing entire sysctl in short writes ... "
  10. set_orig
  11. dd if="${TEST_FILE}" of="${TARGET}" bs=1 2>/dev/null
  12. if ! verify "${TARGET}"; then
  13. echo "FAIL" >&2
  14. rc=1
  15. else
  16. echo "ok"
  17. fi
  18. echo -n "Writing middle of sysctl after unsynchronized seek ... "
  19. set_test
  20. dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 2>/dev/null
  21. if verify "${TARGET}"; then
  22. echo "FAIL" >&2
  23. rc=1
  24. else
  25. echo "ok"
  26. fi
  27. echo -n "Checking sysctl maxlen is at least $MAXLEN ... "
  28. set_orig
  29. perl -e 'print "A" x ('"${MAXLEN}"'-2), "B";' | \
  30. dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
  31. if ! grep -q B "${TARGET}"; then
  32. echo "FAIL" >&2
  33. rc=1
  34. else
  35. echo "ok"
  36. fi
  37. echo -n "Checking sysctl keeps original string on overflow append ... "
  38. set_orig
  39. perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
  40. dd of="${TARGET}" bs=$(( MAXLEN - 1 )) 2>/dev/null
  41. if grep -q B "${TARGET}"; then
  42. echo "FAIL" >&2
  43. rc=1
  44. else
  45. echo "ok"
  46. fi
  47. echo -n "Checking sysctl stays NULL terminated on write ... "
  48. set_orig
  49. perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
  50. dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
  51. if grep -q B "${TARGET}"; then
  52. echo "FAIL" >&2
  53. rc=1
  54. else
  55. echo "ok"
  56. fi
  57. echo -n "Checking sysctl stays NULL terminated on overwrite ... "
  58. set_orig
  59. perl -e 'print "A" x ('"${MAXLEN}"'-1), "BB";' | \
  60. dd of="${TARGET}" bs=$(( $MAXLEN + 1 )) 2>/dev/null
  61. if grep -q B "${TARGET}"; then
  62. echo "FAIL" >&2
  63. rc=1
  64. else
  65. echo "ok"
  66. fi
  67. exit $rc