summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWan-Teh Chang <wtc@google.com>2013-10-30 12:15:55 -0700
committerWan-Teh Chang <wtc@google.com>2013-10-30 12:15:55 -0700
commite6aedcd436b50c68db7129ac2bb04cc95a855c16 (patch)
treed898313a84115418bb1aae2631cca797529b9eb8
parent7d919144e9b6b84aee6314805369af8d040c3cdd (diff)
downloadnspr-hg-e6aedcd436b50c68db7129ac2bb04cc95a855c16.tar.gz
Bug 927687: Avoid unsigned integer wrapping in PL_ArenaAllocate. r=rrelyea.NSPR_4_10_2_BETA2
-rw-r--r--lib/ds/plarena.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/ds/plarena.c b/lib/ds/plarena.c
index 352c8a3d..95e1931e 100644
--- a/lib/ds/plarena.c
+++ b/lib/ds/plarena.c
@@ -196,8 +196,12 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
/* attempt to allocate from the heap */
{
PRUint32 sz = PR_MAX(pool->arenasize, nb);
- sz += sizeof *a + pool->mask; /* header and alignment slop */
- a = (PLArena*)PR_MALLOC(sz);
+ if (PR_UINT32_MAX - sz < sizeof *a + pool->mask) {
+ a = NULL;
+ } else {
+ sz += sizeof *a + pool->mask; /* header and alignment slop */
+ a = (PLArena*)PR_MALLOC(sz);
+ }
if ( NULL != a ) {
a->limit = (PRUword)a + sz;
a->base = a->avail = (PRUword)PL_ARENA_ALIGN(pool, a + 1);