pbs_qselect.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # coding: utf-8
  2. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  3. # For more information, contact Altair at www.altair.com.
  4. #
  5. # This file is part of the PBS Professional ("PBS Pro") software.
  6. #
  7. # Open Source License Information:
  8. #
  9. # PBS Pro is free software. You can redistribute it and/or modify it under the
  10. # terms of the GNU Affero General Public License as published by the Free
  11. # Software Foundation, either version 3 of the License, or (at your option) any
  12. # later version.
  13. #
  14. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. # FOR A PARTICULAR PURPOSE.
  17. # See the GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Commercial License Information:
  23. #
  24. # For a copy of the commercial license terms and conditions,
  25. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  26. # or contact the Altair Legal Department.
  27. #
  28. # Altair’s dual-license business model allows companies, individuals, and
  29. # organizations to create proprietary derivative works of PBS Pro and
  30. # distribute them - whether embedded or bundled with other software -
  31. # under a commercial license agreement.
  32. #
  33. # Use of Altair’s trademarks, including but not limited to "PBS™",
  34. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  35. # trademark licensing policies.
  36. from tests.functional import *
  37. class TestQselect(TestFunctional):
  38. """
  39. Test suite for PBSPro's qselect command
  40. """
  41. def test_qselect_buffer_overflow(self):
  42. """
  43. Check that various qselect option arguments does not buffer overflow
  44. """
  45. # test -q option
  46. ret = self.du.run_cmd(cmd=['qselect', '-q',
  47. ('a' * 30) + '@' + ('b' * 30)])
  48. self.assertNotEqual(ret, None)
  49. self.assertIn('err', ret)
  50. self.assertIn('qselect: illegally formed destination: aaaaaaaaaaaaaaaa'
  51. 'aaaaaaaaaaaaaa@bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
  52. ret['err'])
  53. # test -c
  54. ret = self.du.run_cmd(cmd=['qselect', '-c.abcd.w'])
  55. self.assertNotEqual(ret, None)
  56. self.assertIn('err', ret)
  57. self.assertIn('qselect: illegal -c value', ret['err'])
  58. ret = self.du.run_cmd(cmd=['qselect', '-c.eq.abcdefg'])
  59. self.assertNotEqual(ret, None)
  60. self.assertIn('err', ret)
  61. self.assertIn('qselect: illegal -c value', ret['err'])
  62. # test -a
  63. ret = self.du.run_cmd(cmd=['qselect', '-a.ne.' + ('1' * 100)])
  64. self.assertNotEqual(ret, None)
  65. self.assertIn('err', ret)
  66. self.assertIn('qselect: illegal -a value', ret['err'])
  67. ret = self.du.run_cmd(cmd=['qselect', '-a.abcd.5001011212'])
  68. self.assertNotEqual(ret, None)
  69. self.assertIn('err', ret)
  70. self.assertIn('qselect: illegal -a value', ret['err'])
  71. # test accounting string buf and optarg buf using -A
  72. ret = self.du.run_cmd(cmd=['qselect', '-A', ('a' * 300)])
  73. self.assertNotEqual(ret, None)
  74. self.assertIn('err', ret)
  75. self.assertEqual(ret['err'], [])
  76. # test -l
  77. ret = self.du.run_cmd(cmd=['qselect', '-l',
  78. ('a' * 300) + '.abcd.' + ('b' * 300)])
  79. self.assertNotEqual(ret, None)
  80. self.assertIn('err', ret)
  81. self.assertIn('qselect: illegal -l value', ret['err'])
  82. # test -N
  83. ret = self.du.run_cmd(cmd=['qselect', '-N', ('a' * 300)])
  84. self.assertNotEqual(ret, None)
  85. self.assertIn('err', ret)
  86. self.assertIn('qselect: illegal -N value', ret['err'])
  87. # test -u
  88. ret = self.du.run_cmd(cmd=['qselect', '-u',
  89. ('a' * 300) + '@' + ('b' * 300)])
  90. self.assertNotEqual(ret, None)
  91. self.assertIn('err', ret)
  92. self.assertIn('qselect: illegal -u value', ret['err'])
  93. # test -S
  94. ret = self.du.run_cmd(cmd=['qselect', '-s', 'ABCD'])
  95. self.assertNotEqual(ret, None)
  96. self.assertIn('err', ret)
  97. self.assertIn('qselect: illegal -s value', ret['err'])
  98. # test -t
  99. ret = self.du.run_cmd(cmd=['qselect', '-t',
  100. ('a' * 90) + '.eq.' + ('1' * 90)])
  101. self.assertNotEqual(ret, None)
  102. self.assertIn('err', ret)
  103. self.assertIn('qselect: illegal -t value', ret['err'])