From: Georg Brandl Date: Fri, 13 Feb 2009 11:01:07 +0000 (+0000) Subject: #3694: fix an "XXX undetected error" leak in struct. X-Git-Tag: v3.1a1~188 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=75c3d6ff092f67d1c5aff1d05fcdef1ef1a5bae3;p=thirdparty%2FPython%2Fcpython.git #3694: fix an "XXX undetected error" leak in struct. --- diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 2bc92f3b3943..3d5e0287281c 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -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) diff --git a/Modules/_struct.c b/Modules/_struct.c index 94cb303679e6..57441c4338c8 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -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;