]> granicus.if.org Git - python/commitdiff
Merged revisions 77499 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 14 Jan 2010 17:34:48 +0000 (17:34 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 14 Jan 2010 17:34:48 +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 8b4d26899303c13442b3d680e0f456784d48e55d..c41722c72f0fcee744e43602cef1310c7d7ab279 100644 (file)
@@ -717,6 +717,12 @@ class ReTests(unittest.TestCase):
         self.assertRaises(ValueError, re.compile, '(?a)\w', re.UNICODE)
         self.assertRaises(ValueError, re.compile, '(?au)\w')
 
+    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 a577e65a239c089a2f5e6b3d1dec2a526305ffdc..f2e2fed6ca68d40f93b744c5c9bf2600e249abda 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -213,6 +213,9 @@ C-API
 Library
 -------
 
+- Issue #3299: Fix possible crash in the _sre module when given bad
+  argument values in debug mode.  Patch by Victor Stinner.
+
 - Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
   Patch by Brian Curtin.
 
index 596fd19dfdb573218313f5d8e01706a2055d1c48..7b3ee5fe3a8ed9b1670d9652da94151f1b610df6 100644 (file)
@@ -2674,6 +2674,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;
 
@@ -2689,7 +2693,7 @@ _compile(PyObject* self_, PyObject* args)
     }
 
     if (PyErr_Occurred()) {
-        PyObject_DEL(self);
+        Py_DECREF(self);
         return NULL;
     }
 
@@ -3730,7 +3734,7 @@ static void
 scanner_dealloc(ScannerObject* self)
 {
     state_fini(&self->state);
-    Py_DECREF(self->pattern);
+    Py_XDECREF(self->pattern);
     PyObject_DEL(self);
 }
 
@@ -3860,10 +3864,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;
     }