diff options
author | otto <> | 2012-02-29 08:44:14 +0000 |
---|---|---|
committer | otto <> | 2012-02-29 08:44:14 +0000 |
commit | 07bdd2da84aefcd4aea33b9d8634a6eaae2d4409 (patch) | |
tree | af2481c3937982c91dc0206e8088e6a74cf4a4ef | |
parent | 63b3f8e909c5a7d8692c979173eb2eb59e2de360 (diff) | |
download | openbsd-07bdd2da84aefcd4aea33b9d8634a6eaae2d4409.tar.gz openbsd-07bdd2da84aefcd4aea33b9d8634a6eaae2d4409.tar.bz2 openbsd-07bdd2da84aefcd4aea33b9d8634a6eaae2d4409.zip |
- Test for the retrieved page address not being NULL. This turns free((void*)1)
into an bogus pointer error instead of a segfault.
- Document that we use the assumption that a non-MAP_FIXED mmap() with
hint 0 never returns NULL.
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 5fc75c2c75..6aba00e4a0 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.140 2011/10/06 14:37:04 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.141 2012/02/29 08:44:14 otto Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> |
4 | * | 4 | * |
@@ -724,6 +724,11 @@ alloc_chunk_info(struct dir_info *d, int bits) | |||
724 | return p; | 724 | return p; |
725 | } | 725 | } |
726 | 726 | ||
727 | |||
728 | /* | ||
729 | * The hashtable uses the assumption that p is never NULL. This holds since | ||
730 | * non-MAP_FIXED mappings with hint 0 start at BRKSIZ. | ||
731 | */ | ||
727 | static int | 732 | static int |
728 | insert(struct dir_info *d, void *p, size_t sz, void *f) | 733 | insert(struct dir_info *d, void *p, size_t sz, void *f) |
729 | { | 734 | { |
@@ -774,7 +779,7 @@ find(struct dir_info *d, void *p) | |||
774 | q = MASK_POINTER(r); | 779 | q = MASK_POINTER(r); |
775 | STATS_INC(d->find_collisions); | 780 | STATS_INC(d->find_collisions); |
776 | } | 781 | } |
777 | return q == p ? &d->r[index] : NULL; | 782 | return (q == p && r != NULL) ? &d->r[index] : NULL; |
778 | } | 783 | } |
779 | 784 | ||
780 | static void | 785 | static void |