summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2024-04-14 17:47:42 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2024-04-14 17:47:42 +0000
commit884788ea3ecedfdfe8ae9f3d971ab404a9650202 (patch)
tree0b2ffb9efb38adcf396950c9d014a6341bde7537
parent066c49a4aba0f5dd9d6a5420b697de839ef66dc0 (diff)
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@
-rw-r--r--regress/lib/libc/malloc/malloc_errs/malloc_errs.c14
1 files 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 <otto@drijf.net>
*
@@ -20,6 +20,7 @@
#include <err.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <signal.h>
#include <unistd.h>
@@ -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);