Skip to content

Commit db5f8fc

Browse files
committed
(Merge 3.4) Issue #11259: asynchat.async_chat().set_terminator() now raises a
ValueError if the number of received bytes is negative.
2 parents 7b9328f + 630a4f6 commit db5f8fc

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Lib/asynchat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def set_terminator(self, term):
9999
"""
100100
if isinstance(term, str) and self.use_encoding:
101101
term = bytes(term, self.encoding)
102+
elif isinstance(term, int) and term < 0:
103+
raise ValueError('the number of received bytes must be positive')
102104
self.terminator = term
103105

104106
def get_terminator(self):

Lib/test/test_asynchat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,13 @@ def test_given_list(self):
311311
self.assertEqual(f.pop(), (0, None))
312312

313313

314+
class TestNotConnected(unittest.TestCase):
315+
def test_disallow_negative_terminator(self):
316+
# Issue #11259
317+
client = asynchat.async_chat()
318+
self.assertRaises(ValueError, client.set_terminator, -1)
319+
320+
321+
314322
if __name__ == "__main__":
315323
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ Core and Builtins
108108
Library
109109
-------
110110

111+
- Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
112+
if the number of received bytes is negative.
113+
111114
- Issue #12523: asynchat.async_chat.push() now raises a TypeError if it doesn't
112115
get a bytes string
113116

0 commit comments

Comments
 (0)