From 57895cdc764809ad29336431ee6b43c68fe15f15 Mon Sep 17 00:00:00 2001 From: Colin Percival Date: Wed, 22 Apr 2009 14:07:14 +0000 Subject: Don't leak information via uninitialized space in db(3) records. [09:07] Sanity-check string lengths in order to stop OpenSSL crashing when printing corrupt BMPString or UniversalString objects. [09:08] Security: FreeBSD-SA-09:07.libc Security: FreeBSD-SA-09:08.openssl Security: CVE-2009-0590 Approved by: re (kensmith) Approved by: so (cperciva) --- lib/libc/db/btree/bt_split.c | 2 +- lib/libc/db/hash/hash_buf.c | 9 ++++++--- lib/libc/db/mpool/mpool.c | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/db/btree/bt_split.c b/lib/libc/db/btree/bt_split.c index dc2791762af0..94fa15317d8f 100644 --- a/lib/libc/db/btree/bt_split.c +++ b/lib/libc/db/btree/bt_split.c @@ -381,7 +381,7 @@ bt_page(t, h, lp, rp, skip, ilen) } /* Put the new left page for the split into place. */ - if ((l = (PAGE *)malloc(t->bt_psize)) == NULL) { + if ((l = (PAGE *)calloc(1, t->bt_psize)) == NULL) { mpool_put(t->bt_mp, r, 0); return (NULL); } diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c index db8ad1a3db24..0882eb315a49 100644 --- a/lib/libc/db/hash/hash_buf.c +++ b/lib/libc/db/hash/hash_buf.c @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef DEBUG #include @@ -174,12 +175,12 @@ newbuf(hashp, addr, prev_bp) */ if (hashp->nbufs || (bp->flags & BUF_PIN)) { /* Allocate a new one */ - if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL) + if ((bp = (BUFHEAD *)calloc(1, sizeof(BUFHEAD))) == NULL) return (NULL); #ifdef PURIFY memset(bp, 0xff, sizeof(BUFHEAD)); #endif - if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) { + if ((bp->page = (char *)calloc(1, hashp->BSIZE)) == NULL) { free(bp); return (NULL); } @@ -328,8 +329,10 @@ __buf_free(hashp, do_free, to_disk) } /* Check if we are freeing stuff */ if (do_free) { - if (bp->page) + if (bp->page) { + (void)memset(bp->page, 0, hashp->BSIZE); free(bp->page); + } BUF_REMOVE(bp); free(bp); bp = LRU; diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c index aedf1fd0115f..24860b2043bd 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -343,7 +343,7 @@ mpool_bkt(mp) return (bp); } -new: if ((bp = (BKT *)malloc(sizeof(BKT) + mp->pagesize)) == NULL) +new: if ((bp = (BKT *)calloc(1, sizeof(BKT) + mp->pagesize)) == NULL) return (NULL); #ifdef STATISTICS ++mp->pagealloc; -- cgit v1.3