[Python-checkins] r77501 - in python/branches/py3k: Lib/test/test_re.py Misc/NEWS Modules/_sre.c

antoine.pitrou python-checkins at python.org
Thu Jan 14 18:34:49 CET 2010


Author: antoine.pitrou
Date: Thu Jan 14 18:34:48 2010
New Revision: 77501

Log:
Merged revisions 77499 via svnmerge from 
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.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_re.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/_sre.c

Modified: python/branches/py3k/Lib/test/test_re.py
==============================================================================
--- python/branches/py3k/Lib/test/test_re.py	(original)
+++ python/branches/py3k/Lib/test/test_re.py	Thu Jan 14 18:34:48 2010
@@ -717,6 +717,12 @@
         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

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Jan 14 18:34:48 2010
@@ -213,6 +213,9 @@
 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.
 

Modified: python/branches/py3k/Modules/_sre.c
==============================================================================
--- python/branches/py3k/Modules/_sre.c	(original)
+++ python/branches/py3k/Modules/_sre.c	Thu Jan 14 18:34:48 2010
@@ -2674,6 +2674,10 @@
     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 @@
     }
 
     if (PyErr_Occurred()) {
-        PyObject_DEL(self);
+        Py_DECREF(self);
         return NULL;
     }
 
@@ -3730,7 +3734,7 @@
 scanner_dealloc(ScannerObject* self)
 {
     state_fini(&self->state);
-    Py_DECREF(self->pattern);
+    Py_XDECREF(self->pattern);
     PyObject_DEL(self);
 }
 
@@ -3860,10 +3864,11 @@
     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;
     }
 


More information about the Python-checkins mailing list