bin/83361: [ PATCH ] Incorrect malloc failures handling within libdisk code

Dan Lukes dan at obluda.cz
Tue Jul 12 23:50:14 GMT 2005


>Number:         83361
>Category:       bin
>Synopsis:       [ PATCH ] Incorrect malloc failures handling within libdisk code
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 12 23:50:13 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Dan Lukes
>Release:        FreeBSD 5.4-STABLE i386
>Organization:
Obludarium
>Environment:
System: FreeBSD 5.4-STABLE #8: Sat Jul 9 16:31:08 CEST 2005 i386
lib/libdisk/write_ia64_disk.c,v 1.15 2004/01/30 20:52:54 marcel
lib/libdisk/write_sparc64_disk.c,v 1.8 2003/04/22 05:34:35 phk

>Description:
	Incorrect malloc failures handling can cause dereferencing of NULL
>How-To-Repeat:
>Fix:

--- patch begins here ---
--- lib/libdisk/write_ia64_disk.c.ORIG	Thu Feb  5 20:18:39 2004
+++ lib/libdisk/write_ia64_disk.c	Wed Jul 13 01:25:04 2005
@@ -245,7 +245,7 @@
 	if (sav > 0) {
 		save = malloc(sav * sizeof(struct gpt_ent));
 		if (save == NULL)
-			abort();
+			return(ENOMEM);
 		sav = 0;
 		for (c = disk->chunks->part; c != NULL; c = c->next) {
 			if ((c->flags & CHUNK_HAS_INDEX)) {
@@ -332,6 +332,8 @@
 		bufsz += disk->sector_size;
 	bufsz = (bufsz / disk->sector_size) * disk->sector_size;
 	buffer = calloc(1, bufsz);
+	if (buffer == NULL)
+		return (ENOMEM);
 
 	memcpy(buffer, &hdr[0], sizeof(struct gpt_hdr));
 	off = hdr[0].hdr_lba_self * disk->sector_size;
--- lib/libdisk/write_sparc64_disk.c.ORIG	Wed Apr 23 01:44:38 2003
+++ lib/libdisk/write_sparc64_disk.c	Wed Jul 13 01:36:34 2005
@@ -44,10 +44,13 @@
 	fd = open(device, O_RDWR);
 	if (fd < 0) {
 		warn("open(%s) failed", device);
-		return (1);
+		return (errno);
 	}
 
-	sl = calloc(sizeof *sl, 1);
+	if ((sl = calloc(sizeof *sl, 1)) == NULL) {
+		close(fd);
+		return(ENOMEM);
+	}
 	c = d1->chunks;
 	c2 = c->part;
 	secpercyl = d1->bios_sect * d1->bios_hd;
--- patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list