]> granicus.if.org Git - python/commitdiff
Merged revisions 74167 via svnmerge from
authorGeorg Brandl <georg@python.org>
Wed, 22 Jul 2009 12:03:09 +0000 (12:03 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 22 Jul 2009 12:03:09 +0000 (12:03 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74167 | georg.brandl | 2009-07-22 13:57:15 +0200 (Mi, 22 Jul 2009) | 1 line

  Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
........

Lib/test/test_builtin.py
Misc/NEWS
Objects/bytearrayobject.c

index 6671f2c02ebb2611314fcae3c0e5494205e0c0f0..910658dea3d535d7c8ab543c361e8a8bc5e0d2c4 100644 (file)
@@ -1469,6 +1469,11 @@ class BuiltinTest(unittest.TestCase):
         self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65)
         self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65)
 
+    def test_bytearray_translate(self):
+        x = bytearray("abc")
+        self.assertRaises(ValueError, x.translate, "1", 1)
+        self.assertRaises(TypeError, x.translate, "1"*256, 1)
+
 class TestSorted(unittest.TestCase):
 
     def test_basic(self):
index e0cb38d73fef8f05e34ed3523043ee4a8b9bcd80..df3c2a53b2d86d90de8faa6e856f3474ddbf2da7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6.3
 Core and Builtins
 -----------------
 
+- Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
+
 - Issue #6070: On posix platforms import no longer copies the execute bit
   from the .py file to the .pyc file if it is set.
 
index b5dd81b3b865aa0aa02960969bb7aa4e5c2ea924..7eafce784f0a2cbf777c25013d4c58d3685c44b8 100644 (file)
@@ -1458,15 +1458,14 @@ bytes_translate(PyByteArrayObject *self, PyObject *args)
     if (vtable.len != 256) {
         PyErr_SetString(PyExc_ValueError,
                         "translation table must be 256 characters long");
-        result = NULL;
-        goto done;
+        PyBuffer_Release(&vtable);
+        return NULL;
     }
 
     if (delobj != NULL) {
         if (_getbuffer(delobj, &vdel) < 0) {
-            result = NULL;
-            delobj = NULL;  /* don't try to release vdel buffer on exit */
-            goto done;
+            PyBuffer_Release(&vtable);
+           return NULL;
         }
     }
     else {