diff Modules/parsermodule.c @ 62787:c6f16b8cb858

Issue #9130: Fix validation of relative imports in parser module.
author Mark Dickinson <dickinsm@gmail.com>
date Sun, 04 Jul 2010 18:11:51 +0000
parents 1eaf4bbe4b1c
children fb360c079059
line wrap: on
line diff
--- a/Modules/parsermodule.c	Sun Jul 04 17:47:30 2010 +0000
+++ b/Modules/parsermodule.c	Sun Jul 04 18:11:51 2010 +0000
@@ -1767,8 +1767,8 @@
         return i-1;
 }
 
-/* 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' |
- *     import_as_names
+/* import_from: ('from' ('.'* dotted_name | '.'+)
+ *               'import' ('*' | '(' import_as_names ')' | import_as_names))
  */
 static int
 validate_import_from(node *tree)
@@ -1778,7 +1778,8 @@
         int havename = (TYPE(CHILD(tree, ndots + 1)) == dotted_name);
         int offset = ndots + havename;
         int res = validate_ntype(tree, import_from)
-                && (nch >= 4 + ndots)
+                && (offset >= 1)
+                && (nch >= 3 + offset)
                 && validate_name(CHILD(tree, 0), "from")
                 && (!havename || validate_dotted_name(CHILD(tree, ndots + 1)))
                 && validate_name(CHILD(tree, offset + 1), "import");