This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] malloc.c fix for MALLOC_ALIGN_MASK tests.
- From: Peter Bergner <bergner at vnet dot ibm dot com>
- To: libc-alpha at sources dot redhat dot com
- Cc: Albert Sidelnik <sidelnik at us dot ibm dot com>, Wolfram Gloger <wg at malloc dot de>
- Date: Thu, 15 Sep 2005 10:35:45 -0500
- Subject: [PATCH] malloc.c fix for MALLOC_ALIGN_MASK tests.
The following patch by Wolfram fixed a problem in malloc.c where we were
testing the chunk pointer for proper alignment instead of the mem pointer,
which doesn't work for arches defining MALLOC_ALIGN > 8.
http://sourceware.org/ml/libc-alpha/2003-01/msg00324.html
It seems there are a few other locations where we are doing that which
the following patch fixes up.
Peter
2005-09-15 Peter Bergner <bergner@vnet.ibm.com>
* malloc/malloc.c (public_rEALLOc): Check alignment of oldmem
pointer, not of the computed chunk. Bug report from Albert
Sidelnik <sidelnik@us.ibm.com>.
(_int_free): Likewise for mem.
(_int_realloc): Likewise for oldmem.
Index: malloc/malloc.c
===================================================================
RCS file: /cvs/glibc/libc/malloc/malloc.c,v
retrieving revision 1.149
diff -u -p -r1.149 malloc.c
--- malloc/malloc.c 12 Sep 2005 14:02:14 -0000 1.149
+++ malloc/malloc.c 14 Sep 2005 20:10:31 -0000
@@ -3454,7 +3454,7 @@ public_rEALLOc(Void_t* oldmem, size_t by
Therefore we can exclude some size values which might appear
here by accident or by "design" from some intruder. */
if (__builtin_expect ((uintptr_t) oldp > (uintptr_t) -oldsize, 0)
- || __builtin_expect ((uintptr_t) oldp & MALLOC_ALIGN_MASK, 0))
+ || __builtin_expect ((uintptr_t) oldmem & MALLOC_ALIGN_MASK, 0))
{
malloc_printerr (check_action, "realloc(): invalid pointer", oldmem);
return NULL;
@@ -4268,7 +4268,7 @@ _int_free(mstate av, Void_t* mem)
Therefore we can exclude some size values which might appear
here by accident or by "design" from some intruder. */
if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0)
- || __builtin_expect ((uintptr_t) p & MALLOC_ALIGN_MASK, 0))
+ || __builtin_expect ((uintptr_t) mem & MALLOC_ALIGN_MASK, 0))
{
errstr = "free(): invalid pointer";
errout:
@@ -4608,7 +4608,7 @@ _int_realloc(mstate av, Void_t* oldmem,
oldsize = chunksize(oldp);
/* Simple tests for old block integrity. */
- if (__builtin_expect ((uintptr_t) oldp & MALLOC_ALIGN_MASK, 0))
+ if (__builtin_expect ((uintptr_t) oldmem & MALLOC_ALIGN_MASK, 0))
{
errstr = "realloc(): invalid pointer";
errout: