Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0560e8a

Browse files
committed
Merged revisions 77501 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ................ r77501 | antoine.pitrou | 2010-01-14 18:34:48 +0100 (jeu., 14 janv. 2010) | 10 lines Merged revisions 77499 via svnmerge from svn+ssh://[email protected]/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. ........ ................
1 parent 9000c16 commit 0560e8a

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

Lib/test/test_re.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,12 @@ def test_ascii_and_unicode_flag(self):
696696
self.assertRaises(ValueError, re.compile, '(?a)\w', re.UNICODE)
697697
self.assertRaises(ValueError, re.compile, '(?au)\w')
698698

699+
def test_dealloc(self):
700+
# issue 3299: check for segfault in debug build
701+
import _sre
702+
long_overflow = sys.maxsize + 2
703+
self.assertRaises(TypeError, re.finditer, "a", {})
704+
self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
699705

700706
def run_re_tests():
701707
from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ Core and Builtins
6565
Library
6666
-------
6767

68+
- Issue #3299: Fix possible crash in the _sre module when given bad
69+
argument values in debug mode. Patch by Victor Stinner.
70+
6871
- Issue #7681: Use floor division in appropiate places in the wave module.
6972

7073
- Issue #5372: Drop the reuse of .o files in Distutils' ccompiler (since

Modules/_sre.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,10 @@ _compile(PyObject* self_, PyObject* args)
26742674
self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n);
26752675
if (!self)
26762676
return NULL;
2677+
self->weakreflist = NULL;
2678+
self->pattern = NULL;
2679+
self->groupindex = NULL;
2680+
self->indexgroup = NULL;
26772681

26782682
self->codesize = n;
26792683

@@ -2689,7 +2693,7 @@ _compile(PyObject* self_, PyObject* args)
26892693
}
26902694

26912695
if (PyErr_Occurred()) {
2692-
PyObject_DEL(self);
2696+
Py_DECREF(self);
26932697
return NULL;
26942698
}
26952699

@@ -3730,7 +3734,7 @@ static void
37303734
scanner_dealloc(ScannerObject* self)
37313735
{
37323736
state_fini(&self->state);
3733-
Py_DECREF(self->pattern);
3737+
Py_XDECREF(self->pattern);
37343738
PyObject_DEL(self);
37353739
}
37363740

@@ -3860,10 +3864,11 @@ pattern_scanner(PatternObject* pattern, PyObject* args)
38603864
self = PyObject_NEW(ScannerObject, &Scanner_Type);
38613865
if (!self)
38623866
return NULL;
3867+
self->pattern = NULL;
38633868

38643869
string = state_init(&self->state, pattern, string, start, end);
38653870
if (!string) {
3866-
PyObject_DEL(self);
3871+
Py_DECREF(self);
38673872
return NULL;
38683873
}
38693874

0 commit comments

Comments
 (0)