Thanks to visit codestin.com
Credit goes to github.com

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

[2.7, 3.6] Fix invalid read memory errors #38

Merged
merged 1 commit into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ast27/Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ ast_for_arguments(struct compiling *c, const node *n)

}
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 */
if (parenthesized && Py_Py3kWarningFlag &&
!ast_warn(c, ch, "parenthesized argument names "
Expand All @@ -862,7 +862,7 @@ ast_for_arguments(struct compiling *c, const node *n)
if (!vararg)
return NULL;
i += 2; /* the 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 DOUBLESTAR:
Expand All @@ -872,7 +872,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:
Expand Down
16 changes: 8 additions & 8 deletions ast3/Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,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:
Expand Down Expand Up @@ -1514,7 +1514,7 @@ ast_for_arguments(struct compiling *c, const node *n)
return NULL;
asdl_seq_SET(posargs, k++, 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 STAR:
Expand All @@ -1530,7 +1530,7 @@ ast_for_arguments(struct compiling *c, const node *n)
int res = 0;
i += 2; /* now follows keyword only arguments */

if (TYPE(CHILD(n, i)) == TYPE_COMMENT) {
if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gvanrossum: This could plausibly be the cause of SystemError: <built-in function _parse> returned a result with an error set with crazy line numbers. The line number here is clearly based on uninitialized memory in the spurious case.

ast_error(c, CHILD(n, i),
"bare * has associated type comment");
return NULL;
Expand All @@ -1546,11 +1546,11 @@ ast_for_arguments(struct compiling *c, const node *n)
if (!vararg)
return NULL;

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

if (TYPE(CHILD(n, i)) == TYPE_COMMENT) {
if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) {
Copy link
Collaborator Author

@ddfisher ddfisher Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gvanrossum: It seems very likely to me that this error is the cause of the Function has duplicate type signatures you saw in #36. A spurious type comment here (which could happen from the uninitialized read) would produce the correct error, and this only happens with a *arg, which lines up with what you saw.

vararg->type_comment = NEW_TYPE_COMMENT(CHILD(n, i));
i += 1;
}
Expand All @@ -1572,7 +1572,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:
Expand Down