diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-05-16 23:57:30 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-05-17 00:02:59 -0400 |
commit | 9f25a5529a2e7aa6226851d2b9e3ccc77abdb88a (patch) | |
tree | 7ee6764dc73ed2d0fbd0942a24b88345a4a1c819 /src/common/memarea.c | |
parent | 29bf271ba2deb9714f515e03a9674ac43b9d7156 (diff) | |
download | tor-9f25a5529a2e7aa6226851d2b9e3ccc77abdb88a.tar.gz tor-9f25a5529a2e7aa6226851d2b9e3ccc77abdb88a.zip |
Fix an assertion-failure in memarea_alloc() on 64-bit platforms.
The trick is that we should assert that our next_mem pointer has not
run off the end of the array _before_ we realign the pointer, since
doing that could take us over the end... but only if we're on a system
where malloc() gives us ram in increments smaller than sizeof(void*).
Diffstat (limited to 'src/common/memarea.c')
-rw-r--r-- | src/common/memarea.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/common/memarea.c b/src/common/memarea.c index 7771f2c2ac..1c81e2fd78 100644 --- a/src/common/memarea.c +++ b/src/common/memarea.c @@ -182,6 +182,8 @@ memarea_alloc(memarea_t *area, size_t sz) memarea_chunk_t *chunk = area->first; char *result; tor_assert(chunk); + if (sz == 0) + sz = 1; if (chunk->next_mem+sz > chunk->u.mem+chunk->mem_size) { if (sz+CHUNK_HEADER_SIZE >= CHUNK_SIZE) { /* This allocation is too big. Stick it in a special chunk, and put @@ -198,10 +200,11 @@ memarea_alloc(memarea_t *area, size_t sz) tor_assert(chunk->mem_size >= sz); } result = chunk->next_mem; - chunk->next_mem = realign_pointer(chunk->next_mem + sz); + chunk->next_mem = chunk->next_mem + sz; // XXXX021 remove these once bug 930 is solved. tor_assert(chunk->next_mem >= chunk->u.mem); tor_assert(chunk->next_mem <= chunk->u.mem+chunk->mem_size); + chunk->next_mem = realign_pointer(chunk->next_mem); return result; } @@ -272,7 +275,8 @@ memarea_assert_ok(memarea_t *area) for (chunk = area->first; chunk; chunk = chunk->next_chunk) { tor_assert(chunk->next_mem >= chunk->u.mem); - tor_assert(chunk->next_mem <= chunk->u.mem+chunk->mem_size+MEMAREA_ALIGN); + tor_assert(chunk->next_mem <= + (char*) realign_pointer(chunk->u.mem+chunk->mem_size)); } } |