diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-07-08 19:11:07 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-07-08 19:11:07 (GMT) |
commit | 623fdb9884bb1cf2f38036f0a5e81bccd6b78935 (patch) | |
tree | c873c2ffebf4eecb02c2ae4a21f9d0cf9ef7e0fb | |
parent | cccd1e72481106b0a373117f32fda6261f3141a7 (diff) | |
download | cpython-623fdb9884bb1cf2f38036f0a5e81bccd6b78935.zip cpython-623fdb9884bb1cf2f38036f0a5e81bccd6b78935.tar.gz cpython-623fdb9884bb1cf2f38036f0a5e81bccd6b78935.tar.bz2 |
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
-rw-r--r-- | Parser/node.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Parser/node.c b/Parser/node.c index cccfa82..9ed34b8 100644 --- a/Parser/node.c +++ b/Parser/node.c @@ -18,15 +18,18 @@ PyNode_New(int type) return n; } -/* See comments at XXXROUNDUP below. */ +/* See comments at XXXROUNDUP below. Returns -1 on overflow. */ static int fancy_roundup(int n) { /* Round up to the closest power of 2 >= n. */ int result = 256; assert(n > 128); - while (result < n) + while (result < n) { result <<= 1; + if (result <= 0) + return -1; + } return result; } @@ -62,6 +65,8 @@ PyNode_AddChild(register node *n1, int type, char *str, int lineno) 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; PyMem_RESIZE(n, node, required_capacity); |