From f0600f6414be2ef3fa25531cf962a53364017a95 Mon Sep 17 00:00:00 2001 From: delphij Date: Thu, 2 Apr 2009 17:16:39 +0000 Subject: [PATCH] Bail out when memory allocation is failed, rather than referencing a NULL pointer. PR: kern/94480 Submitted by: Michiel Pelt --- lib/libufs/block.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/libufs/block.c b/lib/libufs/block.c index 5450a5d57739..212cdc66daa2 100644 --- a/lib/libufs/block.c +++ b/lib/libufs/block.c @@ -64,8 +64,10 @@ bread(struct uufsd *disk, ufs2_daddr_t blockno, void *data, size_t size) */ if (((intptr_t)data) & 0x3f) { p2 = malloc(size); - if (p2 == NULL) + if (p2 == NULL) { ERROR(disk, "allocate bounce buffer"); + goto fail; + } } cnt = pread(disk->d_fd, p2, size, (off_t)(blockno * disk->d_bsize)); if (cnt == -1) { @@ -115,8 +117,10 @@ bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size) */ if (((intptr_t)data) & 0x3f) { p2 = malloc(size); - if (p2 == NULL) + if (p2 == NULL) { ERROR(disk, "allocate bounce buffer"); + return (-1); + } memcpy(p2, data, size); data = p2; }