Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

Commit bd92216

Browse files
ddfishergvanrossum
authored andcommitted
[2.7, 3.6] Fix invalid read memory errors (#38)
1 parent 4fbb77e commit bd92216

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

ast27/Python/ast.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ ast_for_arguments(struct compiling *c, const node *n)
846846

847847
}
848848
i += 1; /* the name */
849-
if (TYPE(CHILD(n, i)) == COMMA)
849+
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
850850
i += 1; /* the comma, if present */
851851
if (parenthesized && Py_Py3kWarningFlag &&
852852
!ast_warn(c, ch, "parenthesized argument names "
@@ -862,7 +862,7 @@ ast_for_arguments(struct compiling *c, const node *n)
862862
if (!vararg)
863863
return NULL;
864864
i += 2; /* the star and the name */
865-
if (TYPE(CHILD(n, i)) == COMMA)
865+
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
866866
i += 1; /* the comma, if present */
867867
break;
868868
case DOUBLESTAR:
@@ -872,7 +872,7 @@ ast_for_arguments(struct compiling *c, const node *n)
872872
if (!kwarg)
873873
return NULL;
874874
i += 2; /* the double star and the name */
875-
if (TYPE(CHILD(n, i)) == COMMA)
875+
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
876876
i += 1; /* the comma, if present */
877877
break;
878878
case TYPE_COMMENT:

ast3/Python/ast.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
13721372
goto error;
13731373
asdl_seq_SET(kwonlyargs, j++, arg);
13741374
i += 1; /* the name */
1375-
if (TYPE(CHILD(n, i)) == COMMA)
1375+
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
13761376
i += 1; /* the comma, if present */
13771377
break;
13781378
case TYPE_COMMENT:
@@ -1514,7 +1514,7 @@ ast_for_arguments(struct compiling *c, const node *n)
15141514
return NULL;
15151515
asdl_seq_SET(posargs, k++, arg);
15161516
i += 1; /* the name */
1517-
if (TYPE(CHILD(n, i)) == COMMA)
1517+
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
15181518
i += 1; /* the comma, if present */
15191519
break;
15201520
case STAR:
@@ -1530,7 +1530,7 @@ ast_for_arguments(struct compiling *c, const node *n)
15301530
int res = 0;
15311531
i += 2; /* now follows keyword only arguments */
15321532

1533-
if (TYPE(CHILD(n, i)) == TYPE_COMMENT) {
1533+
if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) {
15341534
ast_error(c, CHILD(n, i),
15351535
"bare * has associated type comment");
15361536
return NULL;
@@ -1546,11 +1546,11 @@ ast_for_arguments(struct compiling *c, const node *n)
15461546
if (!vararg)
15471547
return NULL;
15481548

1549-
i += 2; /* the star and the name */
1550-
if (TYPE(CHILD(n, i)) == COMMA)
1551-
i += 1; /* the comma, if present */
1549+
i += 2; /* the star and the name */
1550+
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
1551+
i += 1; /* the comma, if present */
15521552

1553-
if (TYPE(CHILD(n, i)) == TYPE_COMMENT) {
1553+
if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) {
15541554
vararg->type_comment = NEW_TYPE_COMMENT(CHILD(n, i));
15551555
i += 1;
15561556
}
@@ -1572,7 +1572,7 @@ ast_for_arguments(struct compiling *c, const node *n)
15721572
if (!kwarg)
15731573
return NULL;
15741574
i += 2; /* the double star and the name */
1575-
if (TYPE(CHILD(n, i)) == COMMA)
1575+
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
15761576
i += 1; /* the comma, if present */
15771577
break;
15781578
case TYPE_COMMENT:

0 commit comments

Comments
 (0)