]> granicus.if.org Git - python/commitdiff
Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError if
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 7 Jul 2014 22:26:36 +0000 (00:26 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 7 Jul 2014 22:26:36 +0000 (00:26 +0200)
the number of received bytes is negative.

Lib/asynchat.py
Lib/test/test_asynchat.py
Misc/NEWS

index 682dbd73140fbb05c92b3a9edde262ab4286aa6a..6e16891d439620f6e812db1058a66f9e0b2d95cd 100644 (file)
@@ -99,6 +99,8 @@ class async_chat(asyncore.dispatcher):
         """
         if isinstance(term, str) and self.use_encoding:
             term = bytes(term, self.encoding)
+        elif isinstance(term, int) and term < 0:
+            raise ValueError('the number of received bytes must be positive')
         self.terminator = term
 
     def get_terminator(self):
index 34717399d562fd84e59d18672db47665bf52c2bc..84867ec8206d038f25b240bc7ade6d5a03d948da 100644 (file)
@@ -304,5 +304,13 @@ class TestFifo(unittest.TestCase):
         self.assertEqual(f.pop(), (0, None))
 
 
+class TestNotConnected(unittest.TestCase):
+    def test_disallow_negative_terminator(self):
+        # Issue #11259
+        client = asynchat.async_chat()
+        self.assertRaises(ValueError, client.set_terminator, -1)
+
+
+
 if __name__ == "__main__":
     unittest.main()
index b7e73e9d048268248c380c1bf897b8b2ed2e7395..907e1401a40d31d20a192c725d7919b60bad5ed8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
+  if the number of received bytes is negative.
+
 - Issue #12523: asynchat.async_chat.push() now raises a TypeError if it doesn't
   get a bytes string