1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-28 01:07:08 -05:00

Fix use of aligned_alloc() to be ASan-clean.

aligned_alloc() is used by testsc for all its memory allocation, to
avoid false-positive timing variations that depend on memory alignment
rather than actual secret data. But I'd forgotten that aligned_alloc
requires the allocation size to be a multiple of the requested
alignment.

This showed up when I ran testsc in dry-run mode, and my normal build
happened to be using ASan, which complains at the invalid allocation
size. But it was theoretically a problem in all builds of
testsc. (Though, as far as I'm aware, not practically; and it _only_
affected testsc.)
This commit is contained in:
Simon Tatham 2024-12-04 13:02:05 +01:00
parent 7da3449586
commit c2d7ea8e67

View File

@ -35,7 +35,10 @@ void *safemalloc(size_t factor1, size_t factor2, size_t addend)
#ifdef MINEFIELD
p = minefield_c_malloc(size);
#elif defined ALLOCATION_ALIGNMENT
p = aligned_alloc(ALLOCATION_ALIGNMENT, size);
/* aligned_alloc requires the allocation size to be rounded up */
p = aligned_alloc(
ALLOCATION_ALIGNMENT,
(size + ALLOCATION_ALIGNMENT - 1) & ~(ALLOCATION_ALIGNMENT-1));
#else
p = malloc(size);
#endif