summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorotto <>2024-04-14 17:47:41 +0000
committerotto <>2024-04-14 17:47:41 +0000
commit22372f5970deb0d15444f4ce803b5a44934b22e5 (patch)
tree34e8986e4281cf90b2f3a52699a3f56e17964e2c
parentd9614d1bf1ce1a0212193bc98c06806707629e74 (diff)
downloadopenbsd-22372f5970deb0d15444f4ce803b5a44934b22e5.tar.gz
openbsd-22372f5970deb0d15444f4ce803b5a44934b22e5.tar.bz2
openbsd-22372f5970deb0d15444f4ce803b5a44934b22e5.zip
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@
Diffstat (limited to '')
-rw-r--r--src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c b/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c
index c711980861..486c247f0d 100644
--- a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c
+++ b/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: malloc_errs.c,v 1.4 2023/10/22 12:20:07 otto Exp $ */ 1/* $OpenBSD: malloc_errs.c,v 1.5 2024/04/14 17:47:41 otto Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2023 Otto Moerbeek <otto@drijf.net>
4 * 4 *
@@ -20,6 +20,7 @@
20#include <err.h> 20#include <err.h>
21#include <stdlib.h> 21#include <stdlib.h>
22#include <stdio.h> 22#include <stdio.h>
23#include <stdint.h>
23#include <signal.h> 24#include <signal.h>
24#include <unistd.h> 25#include <unistd.h>
25 26
@@ -231,7 +232,16 @@ void
231t22(void) 232t22(void)
232{ 233{
233 int i, j; 234 int i, j;
234 unsigned char *p = malloc(32); 235 unsigned char *p;
236 while (1) {
237 uintptr_t address;
238 p = malloc(32);
239 address = (uintptr_t)(void *)p;
240 /* we don't want to have a chunk on the last slot of a page */
241 if (address / getpagesize() == (address + 32) / getpagesize())
242 break;
243 free(p);
244 }
235 p[32] = 0; 245 p[32] = 0;
236 for (i = 0; i < 10000; i++) 246 for (i = 0; i < 10000; i++)
237 p = malloc(32); 247 p = malloc(32);