summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorotto <>2017-09-11 18:32:31 +0000
committerotto <>2017-09-11 18:32:31 +0000
commit569a45a7e2fe1602e615e55ed8da6a9a95c3d04a (patch)
tree733ed31eb0e0e9b02e09db619bf67c33afe5a069 /src/lib
parentf63c4fd91b8483c7d4364046fd6ef2d2679dd63a (diff)
downloadopenbsd-569a45a7e2fe1602e615e55ed8da6a9a95c3d04a.tar.gz
openbsd-569a45a7e2fe1602e615e55ed8da6a9a95c3d04a.tar.bz2
openbsd-569a45a7e2fe1602e615e55ed8da6a9a95c3d04a.zip
check double free before canary for chunks; ok millert@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/stdlib/malloc.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index c7ef59b680..1914f90645 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.229 2017/08/20 11:06:16 otto Exp $ */ 1/* $OpenBSD: malloc.c,v 1.230 2017/09/11 18:32:31 otto Exp $ */
2/* 2/*
3 * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -1065,16 +1065,16 @@ find_chunknum(struct dir_info *d, struct region_info *r, void *ptr, int check)
1065 1065
1066 /* Find the chunk number on the page */ 1066 /* Find the chunk number on the page */
1067 chunknum = ((uintptr_t)ptr & MALLOC_PAGEMASK) >> info->shift; 1067 chunknum = ((uintptr_t)ptr & MALLOC_PAGEMASK) >> info->shift;
1068 if (check && info->size > 0) {
1069 validate_canary(d, ptr, info->bits[info->offset + chunknum],
1070 info->size);
1071 }
1072 1068
1073 if ((uintptr_t)ptr & ((1U << (info->shift)) - 1)) 1069 if ((uintptr_t)ptr & ((1U << (info->shift)) - 1))
1074 wrterror(d, "modified chunk-pointer %p", ptr); 1070 wrterror(d, "modified chunk-pointer %p", ptr);
1075 if (info->bits[chunknum / MALLOC_BITS] & 1071 if (info->bits[chunknum / MALLOC_BITS] &
1076 (1U << (chunknum % MALLOC_BITS))) 1072 (1U << (chunknum % MALLOC_BITS)))
1077 wrterror(d, "chunk is already free %p", ptr); 1073 wrterror(d, "chunk is already free %p", ptr);
1074 if (check && info->size > 0) {
1075 validate_canary(d, ptr, info->bits[info->offset + chunknum],
1076 info->size);
1077 }
1078 return chunknum; 1078 return chunknum;
1079} 1079}
1080 1080