[Python-checkins] python/dist/src/Parser node.c,2.17,2.18
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 08 Jul 2002 12:11:10 -0700
Update of /cvsroot/python/python/dist/src/Parser
In directory usw-pr-cvs1:/tmp/cvs-serv21629
Modified Files:
node.c
Log Message:
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Index: node.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/node.c,v
retrieving revision 2.17
retrieving revision 2.18
diff -C2 -d -r2.17 -r2.18
*** node.c 8 Jul 2002 06:32:09 -0000 2.17
--- node.c 8 Jul 2002 19:11:07 -0000 2.18
***************
*** 19,23 ****
}
! /* See comments at XXXROUNDUP below. */
static int
fancy_roundup(int n)
--- 19,23 ----
}
! /* See comments at XXXROUNDUP below. Returns -1 on overflow. */
static int
fancy_roundup(int n)
***************
*** 26,31 ****
int result = 256;
assert(n > 128);
! while (result < n)
result <<= 1;
return result;
}
--- 26,34 ----
int result = 256;
assert(n > 128);
! while (result < n) {
result <<= 1;
+ if (result <= 0)
+ return -1;
+ }
return result;
}
***************
*** 63,66 ****
--- 66,71 ----
current_capacity = XXXROUNDUP(nch);
required_capacity = XXXROUNDUP(nch + 1);
+ if (current_capacity < 0 || required_capacity < 0)
+ return E_OVERFLOW;
if (current_capacity < required_capacity) {
n = n1->n_child;