]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- Issue #3629: Fix sre "bytecode" validator for an end case.
authorGuido van Rossum <guido@python.org>
Wed, 10 Sep 2008 14:27:00 +0000 (14:27 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 10 Sep 2008 14:27:00 +0000 (14:27 +0000)
  Reviewed by Amaury.

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

index 70bd88623d6000918960456163f4a3619396f00a..feb71603e0a1a9a1e8b22a3e3e1c3b698de07627 100644 (file)
@@ -116,6 +116,10 @@ class ReTests(unittest.TestCase):
         self.assertRaises(ValueError, re.findall, pattern, 'A', re.I)
         self.assertRaises(ValueError, re.compile, pattern, re.I)
 
+    def test_bug_3629(self):
+        # A regex that triggered a bug in the sre-code validator
+        re.compile("(?P<quote>)(?(quote))")
+
     def test_sub_template_numeric_escape(self):
         # bug 776311 and friends
         self.assertEqual(re.sub('x', r'\0', 'x'), '\0')
index 08b2020633e9e0f5009751678e76f309ddb5496d..4696a805e3dc6932c15f4febbaa7f63627bf80cb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -68,6 +68,8 @@ C-API
 Library
 -------
 
+- Issue #3629: Fix sre "bytecode" validator for an end case.
+
 - Issue #3811: The Unicode database was updated to 5.1.
 
 - Issue #3809: Fixed spurious 'test.blah' file left behind by test_logging.
index 911192118115546618eb21e59053507256d9efda..1aea53bf94e6ce4e78204d5fa360c5138ef1cb5d 100644 (file)
@@ -2781,17 +2781,18 @@ _compile(PyObject* self_, PyObject* args)
         arg = *code++;                                  \
         VTRACE(("%lu (arg)\n", (unsigned long)arg));    \
     } while (0)
-#define GET_SKIP                                        \
+#define GET_SKIP_ADJ(adj)                               \
     do {                                                \
         VTRACE(("%p= ", code));                         \
         if (code >= end) FAIL;                          \
         skip = *code;                                   \
         VTRACE(("%lu (skip to %p)\n",                   \
                (unsigned long)skip, code+skip));        \
-        if (code+skip < code || code+skip > end)        \
+        if (code+skip-adj < code || code+skip-adj > end)\
             FAIL;                                       \
         code++;                                         \
     } while (0)
+#define GET_SKIP GET_SKIP_ADJ(0)
 
 static int
 _validate_charset(SRE_CODE *code, SRE_CODE *end)
@@ -3098,7 +3099,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
             GET_ARG;
             if (arg >= groups)
                 FAIL;
-            GET_SKIP;
+            GET_SKIP_ADJ(1);
             code--; /* The skip is relative to the first arg! */
             /* There are two possibilities here: if there is both a 'then'
                part and an 'else' part, the generated code looks like: