summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-02-25 09:31:03 (GMT)
committerGitHub <noreply@github.com>2024-02-25 09:31:03 (GMT)
commit79811ededd160b6e8bcfbe4b0f9d5b4589280f19 (patch)
tree1e9378cb6b92d5e6fcc60f896b158ae81e87738c /Lib/test
parent5770006ffac2abd4f1c9fd33bf5015c9ef023576 (diff)
downloadcpython-79811ededd160b6e8bcfbe4b0f9d5b4589280f19.zip
cpython-79811ededd160b6e8bcfbe4b0f9d5b4589280f19.tar.gz
cpython-79811ededd160b6e8bcfbe4b0f9d5b4589280f19.tar.bz2
gh-115886: Handle embedded null characters in shared memory name (GH-115887)
shm_open() and shm_unlink() now check for embedded null characters in the name and raise an error instead of silently truncating it.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/_test_multiprocessing.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index e4183ee..f70a693 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3971,6 +3971,21 @@ class _TestSharedMemory(BaseTestCase):
# test_multiprocessing_spawn, etc) in parallel.
return prefix + str(os.getpid())
+ def test_shared_memory_name_with_embedded_null(self):
+ name_tsmb = self._new_shm_name('test01_null')
+ sms = shared_memory.SharedMemory(name_tsmb, create=True, size=512)
+ self.addCleanup(sms.unlink)
+ with self.assertRaises(ValueError):
+ shared_memory.SharedMemory(name_tsmb + '\0a', create=False, size=512)
+ if shared_memory._USE_POSIX:
+ orig_name = sms._name
+ try:
+ sms._name = orig_name + '\0a'
+ with self.assertRaises(ValueError):
+ sms.unlink()
+ finally:
+ sms._name = orig_name
+
def test_shared_memory_basics(self):
name_tsmb = self._new_shm_name('test01_tsmb')
sms = shared_memory.SharedMemory(name_tsmb, create=True, size=512)
@@ -4105,7 +4120,7 @@ class _TestSharedMemory(BaseTestCase):
self.addCleanup(shm2.unlink)
self.assertEqual(shm2._name, names[1])
- def test_invalid_shared_memory_cration(self):
+ def test_invalid_shared_memory_creation(self):
# Test creating a shared memory segment with negative size
with self.assertRaises(ValueError):
sms_invalid = shared_memory.SharedMemory(create=True, size=-1)