diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2009-12-23 09:46:53 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2009-12-23 09:46:53 (GMT) |
commit | 21c134d0e30b3bcb8733bdd33b9aea10305c2025 (patch) | |
tree | 76312f72a8a9211fbf656c531dfe801feb66c81c /Lib | |
parent | 25339af98d2ce0eac2974ec2ae4edf8142eaccff (diff) | |
download | cpython-21c134d0e30b3bcb8733bdd33b9aea10305c2025.zip cpython-21c134d0e30b3bcb8733bdd33b9aea10305c2025.tar.gz cpython-21c134d0e30b3bcb8733bdd33b9aea10305c2025.tar.bz2 |
Merged revisions 77007 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77007 | gregory.p.smith | 2009-12-23 01:31:11 -0800 (Wed, 23 Dec 2009) | 3 lines
Fix possible integer overflow in lchown and fchown functions. For issue1747858.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_posix.py | 79 |
1 files changed, 54 insertions, 25 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 0929485..88d298b 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -143,32 +143,61 @@ class PosixTester(unittest.TestCase): if hasattr(posix, 'stat'): self.assert_(posix.stat(test_support.TESTFN)) + def _test_all_chown_common(self, chown_func, first_param): + """Common code for chown, fchown and lchown tests.""" + if os.getuid() == 0: + try: + # Many linux distros have a nfsnobody user as MAX_UID-2 + # that makes a good test case for signedness issues. + # http://bugs.python.org/issue1747858 + # This part of the test only runs when run as root. + # Only scary people run their tests as root. + ent = pwd.getpwnam('nfsnobody') + chown_func(first_param, ent.pw_uid, ent.pw_gid) + except KeyError: + pass + else: + # non-root cannot chown to root, raises OSError + self.assertRaises(OSError, chown_func, + first_param, 0, 0) + + # test a successful chown call + chown_func(first_param, os.getuid(), os.getgid()) + + def _test_chown(self): + # raise an OSError if the file does not exist + os.unlink(test_support.TESTFN) + self.assertRaises(OSError, posix.chown, test_support.TESTFN, -1, -1) + + # re-create the file + open(test_support.TESTFN, 'w').close() + self._test_all_chown_common(posix.chown, test_support.TESTFN) + if hasattr(posix, 'chown'): - def test_chown(self): - # raise an OSError if the file does not exist - os.unlink(test_support.TESTFN) - self.assertRaises(OSError, posix.chown, test_support.TESTFN, -1, -1) - - # re-create the file - open(test_support.TESTFN, 'w').close() - if os.getuid() == 0: - try: - # Many linux distros have a nfsnobody user as MAX_UID-2 - # that makes a good test case for signedness issues. - # http://bugs.python.org/issue1747858 - # This part of the test only runs when run as root. - # Only scary people run their tests as root. - ent = pwd.getpwnam('nfsnobody') - posix.chown(test_support.TESTFN, ent.pw_uid, ent.pw_gid) - except KeyError: - pass - else: - # non-root cannot chown to root, raises OSError - self.assertRaises(OSError, posix.chown, - test_support.TESTFN, 0, 0) - - # test a successful chown call - posix.chown(test_support.TESTFN, os.getuid(), os.getgid()) + test_chown = _test_chown + + def _test_fchown(self): + os.unlink(test_support.TESTFN) + + # re-create the file + test_file = open(test_support.TESTFN, 'w') + try: + fd = test_file.fileno() + self._test_all_chown_common(posix.fchown, fd) + finally: + test_file.close() + + if hasattr(posix, 'fchown'): + test_fchown = _test_fchown + + def _test_lchown(self): + os.unlink(test_support.TESTFN) + # create a symlink + os.symlink('/tmp/dummy-symlink-target', test_support.TESTFN) + self._test_all_chown_common(posix.lchown, test_support.TESTFN) + + if hasattr(posix, 'lchown'): + test_lchown = _test_lchown def test_chdir(self): if hasattr(posix, 'chdir'): |