]> granicus.if.org Git - python/commitdiff
#3694: fix an "XXX undetected error" leak in struct.
authorGeorg Brandl <georg@python.org>
Fri, 13 Feb 2009 11:01:07 +0000 (11:01 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 13 Feb 2009 11:01:07 +0000 (11:01 +0000)
Lib/test/test_struct.py
Modules/_struct.c

index 2bc92f3b394357f6a74d668f0389a440e793d3b2..3d5e0287281c55287ec5016d3b008ac79c9b0866 100644 (file)
@@ -524,6 +524,10 @@ class StructTest(unittest.TestCase):
         self.assertRaises(struct.error, s.pack_into, small_buf, 0, test_string)
         self.assertRaises(struct.error, s.pack_into, small_buf, 2, test_string)
 
+        # Test bogus offset (issue 3694)
+        sb = small_buf
+        self.assertRaises(TypeError, struct.pack_into, b'1', sb, None)
+
     def test_pack_into_fn(self):
         test_string = b'Reykjavik rocks, eow!'
         writable_buf = array.array('b', b' '*100)
index 94cb303679e6712b55e39ebcb3a949c810ded011..57441c4338c809161b1bc425190a9f0b34c65c77 100644 (file)
@@ -1785,7 +1785,7 @@ s_pack_into(PyObject *self, PyObject *args)
        assert( buffer_len >= 0 );
 
        /* Extract the offset from the first argument */
-       offset = PyLong_AsSsize_t(PyTuple_GET_ITEM(args, 1));
+       offset = PyNumber_AsSsize_t(PyTuple_GET_ITEM(args, 1), PyExc_IndexError);
        if (offset == -1 && PyErr_Occurred())
                return NULL;