From owner-svn-src-user@FreeBSD.ORG Tue Jul 3 11:30:46 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 896D21065673; Tue, 3 Jul 2012 11:30:46 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 76F8D8FC1A; Tue, 3 Jul 2012 11:30:46 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q63BUkxK041267; Tue, 3 Jul 2012 11:30:46 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q63BUkpd041265; Tue, 3 Jul 2012 11:30:46 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201207031130.q63BUkpd041265@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 3 Jul 2012 11:30:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r238068 - user/ae/bootcode/sys/boot/common X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jul 2012 11:30:46 -0000 Author: ae Date: Tue Jul 3 11:30:45 2012 New Revision: 238068 URL: http://svn.freebsd.org/changeset/base/238068 Log: Add checks for malloc failures. Modified: user/ae/bootcode/sys/boot/common/part.c Modified: user/ae/bootcode/sys/boot/common/part.c ============================================================================== --- user/ae/bootcode/sys/boot/common/part.c Tue Jul 3 11:12:21 2012 (r238067) +++ user/ae/bootcode/sys/boot/common/part.c Tue Jul 3 11:30:45 2012 (r238068) @@ -233,7 +233,13 @@ ptable_gptread(struct ptable *table, voi size_t size; buf = malloc(table->sectorsize); + if (buf == NULL) + return (NULL); tbl = malloc(table->sectorsize * MAXTBLSZ); + if {tbl == NULL} { + free(buf); + return (NULL); + } /* Read the primary GPT header. */ if (dread(dev, buf, 1, 1) != 0) { ptable_close(table); @@ -301,6 +307,8 @@ ptable_gptread(struct ptable *table, voi if (uuid_equal(&ent->ent_type, &gpt_uuid_unused, NULL)) continue; entry = malloc(sizeof(*entry)); + if (entry == NULL) + break; entry->part.start = ent->ent_lba_start; entry->part.end = ent->ent_lba_end; entry->part.index = i + 1; @@ -362,6 +370,8 @@ ptable_ebrread(struct ptable *table, voi index = 5; offset = e1->part.start; buf = malloc(table->sectorsize); + if (buf == NULL) + return (table); for (i = 0; i < MAXEBRENTRIES; i++) { if (offset > table->sectors) break; @@ -378,6 +388,8 @@ ptable_ebrread(struct ptable *table, voi } end = le32toh(dp[0].dp_size); entry = malloc(sizeof(*entry)); + if (entry == NULL) + break; entry->part.start = e1->part.start + start; entry->part.end = entry->part.start + end - 1; entry->part.index = index++; @@ -427,6 +439,8 @@ ptable_bsdread(struct ptable *table, voi return (table); } buf = malloc(table->sectorsize); + if (buf == NULL) + return (table); if (dread(dev, buf, 1, 1) != 0) { DEBUG("read failed"); ptable_close(table); @@ -454,6 +468,8 @@ ptable_bsdread(struct ptable *table, voi if (part->p_size == 0 || part->p_fstype == 0) continue; entry = malloc(sizeof(*entry)); + if (entry == NULL) + break; entry->part.start = le32toh(part->p_offset) - raw_offset; entry->part.end = entry->part.start + le32toh(part->p_size) + 1; @@ -499,6 +515,8 @@ ptable_vtoc8read(struct ptable *table, v if (table->sectorsize != sizeof(struct vtoc8)) return (table); buf = malloc(table->sectorsize); + if (buf == NULL) + return (table); if (dread(dev, buf, 1, 0) != 0) { DEBUG("read failed"); ptable_close(table); @@ -529,6 +547,8 @@ ptable_vtoc8read(struct ptable *table, v dl->part[i].tag == VTOC_TAG_UNASSIGNED) continue; entry = malloc(sizeof(*entry)); + if (entry == NULL) + break; entry->part.start = be32toh(dl->map[i].cyl) * heads * sectors; entry->part.end = be32toh(dl->map[i].nblks) + entry->part.start - 1; @@ -561,6 +581,8 @@ ptable_open(void *dev, off_t sectors, ui #endif table = NULL; buf = malloc(sectorsize); + if (buf == NULL) + return (NULL); /* First, read the MBR. */ if (dread(dev, buf, 1, DOSBBSECTOR) != 0) { DEBUG("read failed"); @@ -568,6 +590,8 @@ ptable_open(void *dev, off_t sectors, ui } table = malloc(sizeof(*table)); + if (table == NULL) + goto out; table->sectors = sectors; table->sectorsize = sectorsize; table->type = PTABLE_NONE; @@ -642,6 +666,8 @@ ptable_open(void *dev, off_t sectors, ui dp[i].dp_typ == DOSPTYP_EXTLBA) has_ext = 1; entry = malloc(sizeof(*entry)); + if (entry == NULL) + break; entry->part.start = start; entry->part.end = start + end - 1; entry->part.index = i + 1;