diff Modules/parsermodule.c @ 62781:be662d124385 2.6

Issue #9130: Fix validation of relative imports in parser module.
author Mark Dickinson <dickinsm@gmail.com>
date Sun, 04 Jul 2010 16:59:04 +0000
parents 124a76ae7a70
children 787b969d37f0
line wrap: on
line diff
--- a/Modules/parsermodule.c	Sun Jul 04 16:28:57 2010 +0000
+++ b/Modules/parsermodule.c	Sun Jul 04 16:59:04 2010 +0000
@@ -1886,8 +1886,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)
@@ -1897,7 +1897,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");