Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/string map enough space for both the page we ...



details:   https://anonhg.NetBSD.org/src/rev/acd8ef518b31
branches:  trunk
changeset: 957403:acd8ef518b31
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Nov 27 16:50:02 2020 +0000

description:
map enough space for both the page we write and the guard so that we make
sure we own the guard page before we set its protection to none. This fixes
random SEGVs where the page we set protection to none probably belonged to
the dynamic linker. Reported by gson@

diffstat:

 tests/lib/libc/string/t_memmem.c |  5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diffs (23 lines):

diff -r 61bdb05f8716 -r acd8ef518b31 tests/lib/libc/string/t_memmem.c
--- a/tests/lib/libc/string/t_memmem.c  Fri Nov 27 16:42:00 2020 +0000
+++ b/tests/lib/libc/string/t_memmem.c  Fri Nov 27 16:50:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_memmem.c,v 1.5 2020/11/27 15:37:06 gson Exp $ */
+/*     $NetBSD: t_memmem.c,v 1.6 2020/11/27 16:50:02 christos Exp $ */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -105,11 +105,12 @@
 {
        static const char str[] = "abcde";
        size_t pg = getpagesize();
-       char *src = mmap(NULL, pg, PROT_READ|PROT_WRITE,
+       char *src = mmap(NULL, 2 * pg, PROT_READ|PROT_WRITE,
            MAP_ANON|MAP_PRIVATE, -1, (off_t)0);
        ATF_CHECK(src != MAP_FAILED);
        char *guard = mmap(src + pg, pg,
            PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, (off_t)0);
+printf("%p\n", guard);
        for (size_t i = 2; i < 5; i++) {
                char *search = src + pg - i;
                char match[sizeof(str)];



Home | Main Index | Thread Index | Old Index