Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Feb 2011 12:07:16 +0000 (UTC)
From:      Bruce Cran <brucec@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r219054 - stable/7/sys/boot/common
Message-ID:  <201102261207.p1QC7G30070874@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: brucec
Date: Sat Feb 26 12:07:16 2011
New Revision: 219054
URL: http://svn.freebsd.org/changeset/base/219054

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

Modified:
  stable/7/sys/boot/common/interp.c
Directory Properties:
  stable/7/sys/   (props changed)
  stable/7/sys/cddl/contrib/opensolaris/   (props changed)
  stable/7/sys/contrib/dev/acpica/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)

Modified: stable/7/sys/boot/common/interp.c
==============================================================================
--- stable/7/sys/boot/common/interp.c	Sat Feb 26 12:04:34 2011	(r219053)
+++ stable/7/sys/boot/common/interp.c	Sat Feb 26 12:07:16 2011	(r219054)
@@ -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;



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