mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them.
This commit is contained in:
parent
2ef7c47844
commit
2b0d2007a1
4 changed files with 50 additions and 7 deletions
|
@ -1169,6 +1169,42 @@ class PosixTester(unittest.TestCase):
|
|||
else:
|
||||
self.fail("No valid path_error2() test for os." + name)
|
||||
|
||||
def test_path_with_null_character(self):
|
||||
fn = support.TESTFN
|
||||
fn_with_NUL = fn + '\0'
|
||||
self.addCleanup(support.unlink, fn)
|
||||
support.unlink(fn)
|
||||
fd = None
|
||||
try:
|
||||
with self.assertRaises(TypeError):
|
||||
fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
|
||||
finally:
|
||||
if fd is not None:
|
||||
os.close(fd)
|
||||
self.assertFalse(os.path.exists(fn))
|
||||
self.assertRaises(TypeError, os.mkdir, fn_with_NUL)
|
||||
self.assertFalse(os.path.exists(fn))
|
||||
open(fn, 'wb').close()
|
||||
self.assertRaises(TypeError, os.stat, fn_with_NUL)
|
||||
|
||||
def test_path_with_null_byte(self):
|
||||
fn = os.fsencode(support.TESTFN)
|
||||
fn_with_NUL = fn + b'\0'
|
||||
self.addCleanup(support.unlink, fn)
|
||||
support.unlink(fn)
|
||||
fd = None
|
||||
try:
|
||||
with self.assertRaises(ValueError):
|
||||
fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
|
||||
finally:
|
||||
if fd is not None:
|
||||
os.close(fd)
|
||||
self.assertFalse(os.path.exists(fn))
|
||||
self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
|
||||
self.assertFalse(os.path.exists(fn))
|
||||
open(fn, 'wb').close()
|
||||
self.assertRaises(ValueError, os.stat, fn_with_NUL)
|
||||
|
||||
class PosixGroupsTester(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue