Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Feb 2011 17:17:05 +0000 (UTC)
From:      Bruce Cran <brucec@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r218974 - in head/sys/boot: common efi/libefi
Message-ID:  <201102231717.p1NHH5q7001489@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: brucec
Date: Wed Feb 23 17:17:05 2011
New Revision: 218974
URL: http://svn.freebsd.org/changeset/base/218974

Log:
  Handle memory allocation failures in include().
  
  PR:		i386/85652
  Submitted by:	Ben Thomas <bthomas at virtualiron.com>
  MFC after:	3 days

Modified:
  head/sys/boot/common/interp.c
  head/sys/boot/efi/libefi/efipart.c

Modified: head/sys/boot/common/interp.c
==============================================================================
--- head/sys/boot/common/interp.c	Wed Feb 23 13:51:41 2011	(r218973)
+++ head/sys/boot/common/interp.c	Wed Feb 23 17:17:05 2011	(r218974)
@@ -246,6 +246,17 @@ include(const char *filename)
 	if (*cp == '\0')
 		continue;	/* ignore empty line, save memory */
 	sp = malloc(sizeof(struct includeline) + strlen(cp) + 1);
+	/* On malloc failure (it happens!), free as much as possible and exit */
+	if (sp == NULL) {
+		while (script != NULL) {
+			se = script;
+			script = script->next;
+			free(se);
+		}
+		sprintf(command_errbuf, "file '%s' line %d: memory allocation "
+		    "failure - aborting\n", filename, line);
+		return (CMD_ERROR);
+	}
 	strcpy(sp->text, cp);
 #ifndef BOOT_FORTH
 	sp->flags = flags;

Modified: head/sys/boot/efi/libefi/efipart.c
==============================================================================
--- head/sys/boot/efi/libefi/efipart.c	Wed Feb 23 13:51:41 2011	(r218973)
+++ head/sys/boot/efi/libefi/efipart.c	Wed Feb 23 17:17:05 2011	(r218974)
@@ -204,7 +204,7 @@ efipart_readwrite(EFI_BLOCK_IO *blkio, i
 	}
 
 	if (EFI_ERROR(status))
-		printf("%s: rw=%d, status=%lu\n", __func__, rw, status);
+		printf("%s: rw=%d, status=%u\n", __func__, rw, status);
 	return (efi_status_to_errno(status));
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201102231717.p1NHH5q7001489>