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

Skip to content

Commit e921e02

Browse files
committed
Fix uninitialized memory read for cases like def(f, *): pass
There's not much interesting here. The old code read uninitialized memory but at worst incremented i past NCH(n), but no bad effects followed from that.
1 parent c3fee69 commit e921e02

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

Python/ast.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,15 +742,21 @@ ast_for_arguments(struct compiling *c, const node *n)
742742
}
743743
assert(TYPE(n) == typedargslist || TYPE(n) == varargslist);
744744

745-
/* first count the number of positional args & defaults */
745+
/* First count the number of positional args & defaults. The
746+
variable i is the loop index for this for loop and the next.
747+
The next loop picks up where the first leaves off.
748+
*/
746749
for (i = 0; i < NCH(n); i++) {
747750
ch = CHILD(n, i);
748751
if (TYPE(ch) == STAR) {
749-
/* skip star and possible argument */
752+
/* skip star */
750753
i++;
751-
i += (TYPE(CHILD(n, i)) == tfpdef
752-
|| TYPE(CHILD(n, i)) == vfpdef);
753-
break;
754+
if (i < NCH(n) && /* skip argument following star */
755+
(TYPE(CHILD(n, i)) == tfpdef ||
756+
TYPE(CHILD(n, i)) == vfpdef)) {
757+
i++;
758+
}
759+
break;
754760
}
755761
if (TYPE(ch) == DOUBLESTAR) break;
756762
if (TYPE(ch) == vfpdef || TYPE(ch) == tfpdef) nposargs++;

0 commit comments

Comments
 (0)