summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2008-04-18 20:18:22 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2008-04-18 20:18:22 +0000
commit5736a8a4b6681c5414f6a97e4b572b7db69f266d (patch)
treec0a80ac0a408072f4e5a8c46369bc346863cf0da /usr.bin
parent22db742c56a14689d61d21e299e9a01d48252e6b (diff)
If memory allocation fails during error message buffering, print all hold
back messages and exit. ok millert
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/pr/pr.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/pr/pr.c b/usr.bin/pr/pr.c
index a83c0642191..29c01f53dd2 100644
--- a/usr.bin/pr/pr.c
+++ b/usr.bin/pr/pr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pr.c,v 1.25 2007/09/03 12:36:09 moritz Exp $ */
+/* $OpenBSD: pr.c,v 1.26 2008/04/18 20:18:21 tobias Exp $ */
/*-
* Copyright (c) 1991 Keith Muller.
@@ -41,7 +41,7 @@ static char copyright[] =
#ifndef lint
/* from: static char sccsid[] = "@(#)pr.c 8.1 (Berkeley) 6/6/93"; */
-static char *rcsid = "$OpenBSD: pr.c,v 1.25 2007/09/03 12:36:09 moritz Exp $";
+static char *rcsid = "$OpenBSD: pr.c,v 1.26 2008/04/18 20:18:21 tobias Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -850,8 +850,13 @@ ferrout(char *fmt, ...)
sigaddset(&block, SIGINT);
sigprocmask(SIG_BLOCK, &block, &oblock);
- vasprintf(&p, fmt, ap);
- f = (struct ferrlist *)malloc(sizeof(*f));
+ if (vasprintf(&p, fmt, ap) == -1 || (f = malloc(sizeof(*f))) == NULL) {
+ flsh_errs();
+ fprintf(stderr, fmt, ap);
+ fputs("pr: memory allocation failed\n", stderr);
+ exit(1);
+ }
+
f->next = NULL;
f->buf = p;
if (ferrhead == NULL)