Pad allocations in setup_{,temp_}malloc for 8-byte alignment

4-byte alignment triggered warnings with clang and -fsanitize=undefined.

Fix #799.

Signed-off-by: Peter Waller <p@pwaller.net>
This commit is contained in:
Peter Waller 2019-12-29 22:58:47 +00:00
parent f67165c2bb
commit 2f18c96cfb

View File

@ -30,7 +30,7 @@
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot // Tom Beaumont Ingo Leitgeb Nicolas Guillemot
// Phillip Bennefall Rohit Thiago Goulart // Phillip Bennefall Rohit Thiago Goulart
// manxorist@github saga musix github:infatum // manxorist@github saga musix github:infatum
// Timur Gagiev Maxwell Koo // Timur Gagiev Maxwell Koo Peter Waller
// //
// Partial history: // Partial history:
// 1.17 - 2019-07-08 - fix CVE-2019-13217..CVE-2019-13223 (by ForAllSecure) // 1.17 - 2019-07-08 - fix CVE-2019-13217..CVE-2019-13223 (by ForAllSecure)
@ -909,7 +909,7 @@ static void *make_block_array(void *mem, int count, int size)
static void *setup_malloc(vorb *f, int sz) static void *setup_malloc(vorb *f, int sz)
{ {
sz = (sz+3) & ~3; sz = (sz+7) & ~7; // round up to nearest 8 for alignment of future allocs.
f->setup_memory_required += sz; f->setup_memory_required += sz;
if (f->alloc.alloc_buffer) { if (f->alloc.alloc_buffer) {
void *p = (char *) f->alloc.alloc_buffer + f->setup_offset; void *p = (char *) f->alloc.alloc_buffer + f->setup_offset;
@ -928,7 +928,7 @@ static void setup_free(vorb *f, void *p)
static void *setup_temp_malloc(vorb *f, int sz) static void *setup_temp_malloc(vorb *f, int sz)
{ {
sz = (sz+3) & ~3; sz = (sz+7) & ~7; // round up to nearest 8 for alignment of future allocs.
if (f->alloc.alloc_buffer) { if (f->alloc.alloc_buffer) {
if (f->temp_offset - sz < f->setup_offset) return NULL; if (f->temp_offset - sz < f->setup_offset) return NULL;
f->temp_offset -= sz; f->temp_offset -= sz;