]> granicus.if.org Git - python/commitdiff
Merged revisions 77499 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 14 Jan 2010 17:34:09 +0000 (17:34 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 14 Jan 2010 17:34:09 +0000 (17:34 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77499 | antoine.pitrou | 2010-01-14 18:25:24 +0100 (jeu., 14 janv. 2010) | 4 lines

  Issue #3299: Fix possible crash in the _sre module when given bad
  argument values in debug mode.  Patch by Victor Stinner.
........

Lib/test/test_re.py
Misc/NEWS
Modules/_sre.c

index feb71603e0a1a9a1e8b22a3e3e1c3b698de07627..c04b626d3cee88287d2c094e4f67ef91d6481c3e 100644 (file)
@@ -685,6 +685,12 @@ class ReTests(unittest.TestCase):
         self.assertEqual(pattern.sub('#', 'a\nb\nc'), 'a#\nb#\nc#')
         self.assertEqual(pattern.sub('#', '\n'), '#\n#')
 
+    def test_dealloc(self):
+        # issue 3299: check for segfault in debug build
+        import _sre
+        long_overflow = sys.maxsize + 2
+        self.assertRaises(TypeError, re.finditer, "a", {})
+        self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
 
 def run_re_tests():
     from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
index 9386a18142b05a2b46e24df74e026ba034346096..a292c74fd3e8eae3ccc3df6fedc82cf0a23f4abd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #3299: Fix possible crash in the _sre module when given bad
+  argument values in debug mode.  Patch by Victor Stinner.
+
 - Issue #5827: Make sure that normpath preserves unicode.  Initial patch
   by Matt Giuca.
 
index 1aea53bf94e6ce4e78204d5fa360c5138ef1cb5d..731b13d1a885083391574f5ce960634297cc2b5a 100644 (file)
@@ -2684,6 +2684,10 @@ _compile(PyObject* self_, PyObject* args)
     self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n);
     if (!self)
         return NULL;
+    self->weakreflist = NULL;
+    self->pattern = NULL;
+    self->groupindex = NULL;
+    self->indexgroup = NULL;
 
     self->codesize = n;
 
@@ -2700,7 +2704,7 @@ _compile(PyObject* self_, PyObject* args)
     }
 
     if (PyErr_Occurred()) {
-        PyObject_DEL(self);
+        Py_DECREF(self);
         return NULL;
     }
 
@@ -3718,7 +3722,7 @@ static void
 scanner_dealloc(ScannerObject* self)
 {
     state_fini(&self->state);
-    Py_DECREF(self->pattern);
+    Py_XDECREF(self->pattern);
     PyObject_DEL(self);
 }
 
@@ -3840,10 +3844,11 @@ pattern_scanner(PatternObject* pattern, PyObject* args)
     self = PyObject_NEW(ScannerObject, &Scanner_Type);
     if (!self)
         return NULL;
+    self->pattern = NULL;
 
     string = state_init(&self->state, pattern, string, start, end);
     if (!string) {
-        PyObject_DEL(self);
+        Py_DECREF(self);
         return NULL;
     }