diff options
author | brucec <brucec@FreeBSD.org> | 2011-02-23 17:17:05 +0000 |
---|---|---|
committer | brucec <brucec@FreeBSD.org> | 2011-02-23 17:17:05 +0000 |
commit | 94fe6c80c71b0f8789aa55d2fd321d78e264b0f3 (patch) | |
tree | 4d9932fd6f6e0fc975405df1221be98394162b2a | |
parent | 05f2685017a9f4f98dd2e2ea77feae637e16e5fa (diff) | |
download | FreeBSD-src-94fe6c80c71b0f8789aa55d2fd321d78e264b0f3.zip FreeBSD-src-94fe6c80c71b0f8789aa55d2fd321d78e264b0f3.tar.gz |
Handle memory allocation failures in include().
PR: i386/85652
Submitted by: Ben Thomas <bthomas at virtualiron.com>
MFC after: 3 days
-rw-r--r-- | sys/boot/common/interp.c | 11 | ||||
-rw-r--r-- | sys/boot/efi/libefi/efipart.c | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/sys/boot/common/interp.c b/sys/boot/common/interp.c index b9343a6..a9370d9 100644 --- a/sys/boot/common/interp.c +++ b/sys/boot/common/interp.c @@ -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; diff --git a/sys/boot/efi/libefi/efipart.c b/sys/boot/efi/libefi/efipart.c index 4abac06..0225d76 100644 --- a/sys/boot/efi/libefi/efipart.c +++ b/sys/boot/efi/libefi/efipart.c @@ -204,7 +204,7 @@ efipart_readwrite(EFI_BLOCK_IO *blkio, int rw, daddr_t blk, daddr_t nblks, } 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)); } |