From 13a1f578cb560c358db56cc1e06595f083545e4f Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 3 Jan 2022 21:11:31 -0500 Subject: [PATCH] use calculated size for overflow tests This greatly reduces how much these tests depend on hard-wired knowledge about the size classes. --- test/simple-memory-corruption/eight_byte_overflow_large.c | 3 ++- test/simple-memory-corruption/eight_byte_overflow_small.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/simple-memory-corruption/eight_byte_overflow_large.c b/test/simple-memory-corruption/eight_byte_overflow_large.c index 3b8c8d3..d6b7544 100644 --- a/test/simple-memory-corruption/eight_byte_overflow_large.c +++ b/test/simple-memory-corruption/eight_byte_overflow_large.c @@ -7,7 +7,8 @@ OPTNONE int main(void) { if (!p) { return 1; } - *(p + 256 * 1024 + 7) = 0; + size_t size = malloc_usable_size(p); + *(p + size + 7) = 0; free(p); return 0; } diff --git a/test/simple-memory-corruption/eight_byte_overflow_small.c b/test/simple-memory-corruption/eight_byte_overflow_small.c index bd2666d..54c0de2 100644 --- a/test/simple-memory-corruption/eight_byte_overflow_small.c +++ b/test/simple-memory-corruption/eight_byte_overflow_small.c @@ -7,7 +7,8 @@ OPTNONE int main(void) { if (!p) { return 1; } - *(p + 8 + 7) ^= 1; + size_t size = malloc_usable_size(p); + *(p + size + 7) ^= 1; free(p); return 0; }