1. Armin Rigo
  2. cpython-withatomic

Commits

Guido van Rossum  committed 95ac698

- Issue #3629: Fix sre "bytecode" validator for an end case.
Reviewed by Amaury.

  • Participants
  • Parent commits c37c7db
  • Branches legacy-trunk

Comments (0)

Files changed (3)

File Lib/test/test_re.py

View file
         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')

File Misc/NEWS

View file
 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.

File Modules/_sre.c

View file
         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)
             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: