From 06a1d8d0309bd17b114dfe01ae51e99a1dc919ef Mon Sep 17 00:00:00 2001 From: otto Date: Sun, 14 Apr 2024 17:47:41 +0000 Subject: [PATCH] t22 and t23 can fail if the first chunk ends up being allocated at the very end of the page. Circumvent that. Reported by and fix ok anton@ --- regress/lib/libc/malloc/malloc_errs/malloc_errs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/regress/lib/libc/malloc/malloc_errs/malloc_errs.c b/regress/lib/libc/malloc/malloc_errs/malloc_errs.c index c711980861a..486c247f0dd 100644 --- a/regress/lib/libc/malloc/malloc_errs/malloc_errs.c +++ b/regress/lib/libc/malloc/malloc_errs/malloc_errs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc_errs.c,v 1.4 2023/10/22 12:20:07 otto Exp $ */ +/* $OpenBSD: malloc_errs.c,v 1.5 2024/04/14 17:47:41 otto Exp $ */ /* * Copyright (c) 2023 Otto Moerbeek * @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -231,7 +232,16 @@ void t22(void) { int i, j; - unsigned char *p = malloc(32); + unsigned char *p; + while (1) { + uintptr_t address; + p = malloc(32); + address = (uintptr_t)(void *)p; + /* we don't want to have a chunk on the last slot of a page */ + if (address / getpagesize() == (address + 32) / getpagesize()) + break; + free(p); + } p[32] = 0; for (i = 0; i < 10000; i++) p = malloc(32); -- 2.20.1