diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-12-06 21:12:28 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-12-06 21:12:28 -0500 |
commit | 2ad9cf52eb9fea12a19bcf893828e1361a0b6546 (patch) | |
tree | ce8ba924d60ba567fb8db75b8bd17ab4c89cfeb1 /src/malloc | |
parent | 5c5e45e58bd0da2d74aea3e6631b240fedd707ef (diff) | |
download | musl-2ad9cf52eb9fea12a19bcf893828e1361a0b6546.tar.gz musl-2ad9cf52eb9fea12a19bcf893828e1361a0b6546.tar.bz2 musl-2ad9cf52eb9fea12a19bcf893828e1361a0b6546.tar.xz musl-2ad9cf52eb9fea12a19bcf893828e1361a0b6546.zip |
fix invalid read in aligned_alloc
in case of mmap-obtained chunks, end points past the end of the
mapping and reading it may fault. since the value is not needed until
after the conditional, move the access to prevent invalid reads.
Diffstat (limited to 'src/malloc')
-rw-r--r-- | src/malloc/aligned_alloc.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/malloc/aligned_alloc.c b/src/malloc/aligned_alloc.c index d623420b..158dba41 100644 --- a/src/malloc/aligned_alloc.c +++ b/src/malloc/aligned_alloc.c @@ -31,8 +31,6 @@ void *aligned_alloc(size_t align, size_t len) return NULL; header = ((size_t *)mem)[-1]; - end = mem + (header & -8); - footer = ((size_t *)end)[-2]; new = (void *)((uintptr_t)mem + align-1 & -align); if (!(header & 7)) { @@ -41,6 +39,9 @@ void *aligned_alloc(size_t align, size_t len) return new; } + end = mem + (header & -8); + footer = ((size_t *)end)[-2]; + ((size_t *)mem)[-1] = header&7 | new-mem; ((size_t *)new)[-2] = footer&7 | new-mem; ((size_t *)new)[-1] = header&7 | end-new; |