diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-03 01:11:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-03 01:11:17 (GMT) |
commit | c2d3f73da780ce4d568f541fb7f55917a814d65c (patch) | |
tree | 99a0e306a1169f0c942dc4db73e5bda15f0b6e1a /Lib | |
parent | 72d445a22e4fe59f11f090762f2517a60e164f40 (diff) | |
download | cpython-c2d3f73da780ce4d568f541fb7f55917a814d65c.zip cpython-c2d3f73da780ce4d568f541fb7f55917a814d65c.tar.gz cpython-c2d3f73da780ce4d568f541fb7f55917a814d65c.tar.bz2 |
gh-96819: multiprocessing.resource_tracker: check if length of pipe write <= 512 (GH-96890)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
(cherry picked from commit 19ca114645bd8796cf4094e152b1fa9944da473d)
Co-authored-by: Koki Saito <49419225+saito828koki@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/multiprocessing/resource_tracker.py | 4 | ||||
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/Lib/multiprocessing/resource_tracker.py b/Lib/multiprocessing/resource_tracker.py index cc42dbd..ea36950 100644 --- a/Lib/multiprocessing/resource_tracker.py +++ b/Lib/multiprocessing/resource_tracker.py @@ -161,10 +161,10 @@ class ResourceTracker(object): def _send(self, cmd, name, rtype): self.ensure_running() msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii') - if len(name) > 512: + if len(msg) > 512: # posix guarantees that writes to a pipe of less than PIPE_BUF # bytes are atomic, and that PIPE_BUF >= 512 - raise ValueError('name too long') + raise ValueError('msg too long') nbytes = os.write(self._fd, msg) assert nbytes == len(msg), "nbytes {0:n} but len(msg) {1:n}".format( nbytes, len(msg)) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 8dced90..be174aa 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -5377,6 +5377,14 @@ class TestResourceTracker(unittest.TestCase): self.assertTrue(is_resource_tracker_reused) + def test_too_long_name_resource(self): + # gh-96819: Resource names that will make the length of a write to a pipe + # greater than PIPE_BUF are not allowed + rtype = "shared_memory" + too_long_name_resource = "a" * (512 - len(rtype)) + with self.assertRaises(ValueError): + resource_tracker.register(too_long_name_resource, rtype) + class TestSimpleQueue(unittest.TestCase): |