Discussion:
[Python-3000-checkins] r65064 - python/branches/py3k/Python/ast.c
jeremy.hylton
2008-07-17 16:37:17 UTC
Permalink
Author: jeremy.hylton
Date: Thu Jul 17 18:37:17 2008
New Revision: 65064

Log:
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.



Modified:
python/branches/py3k/Python/ast.c

Modified: python/branches/py3k/Python/ast.c
==============================================================================
--- python/branches/py3k/Python/ast.c (original)
+++ python/branches/py3k/Python/ast.c Thu Jul 17 18:37:17 2008
@@ -742,15 +742,21 @@
}
assert(TYPE(n) == typedargslist || TYPE(n) == varargslist);

- /* first count the number of positional args & defaults */
+ /* First count the number of positional args & defaults. The
+ variable i is the loop index for this for loop and the next.
+ The next loop picks up where the first leaves off.
+ */
for (i = 0; i < NCH(n); i++) {
ch = CHILD(n, i);
if (TYPE(ch) == STAR) {
- /* skip star and possible argument */
+ /* skip star */
i++;
- i += (TYPE(CHILD(n, i)) == tfpdef
- || TYPE(CHILD(n, i)) == vfpdef);
- break;
+ if (i < NCH(n) && /* skip argument following star */
+ (TYPE(CHILD(n, i)) == tfpdef ||
+ TYPE(CHILD(n, i)) == vfpdef)) {
+ i++;
+ }
+ break;
}
if (TYPE(ch) == DOUBLESTAR) break;
if (TYPE(ch) == vfpdef || TYPE(ch) == tfpdef) nposargs++;

Loading...