]> granicus.if.org Git - python/commitdiff
bpo-36495: Fix two out-of-bounds array reads (GH-12641)
authorBrad Larsen <brad@bradfordlarsen.com>
Mon, 1 Apr 2019 14:36:05 +0000 (10:36 -0400)
committerGuido van Rossum <guido@python.org>
Mon, 1 Apr 2019 14:36:05 +0000 (07:36 -0700)
Research and fix by @bradlarsen.

Python/ast.c

index e9154fecff064b33f7fee23b06d700be6105f301..913e53ad7937d882e493381c19acae509100947f 100644 (file)
@@ -1400,7 +1400,7 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
                     goto error;
                 asdl_seq_SET(kwonlyargs, j++, arg);
                 i += 1; /* the name */
-                if (TYPE(CHILD(n, i)) == COMMA)
+                if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
                     i += 1; /* the comma, if present */
                 break;
             case TYPE_COMMENT:
@@ -1599,7 +1599,7 @@ ast_for_arguments(struct compiling *c, const node *n)
                 if (!kwarg)
                     return NULL;
                 i += 2; /* the double star and the name */
-                if (TYPE(CHILD(n, i)) == COMMA)
+                if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
                     i += 1; /* the comma, if present */
                 break;
             case TYPE_COMMENT: