From da01648b8bb2177933485864ad5494309428d2d8 Mon Sep 17 00:00:00 2001 From: millert Date: Mon, 12 Oct 2015 21:32:27 +0000 Subject: [PATCH] Add missing checks for write errors; OK eric@ --- usr.sbin/smtpd/enqueue.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c index d05bbd89149..7d8c3fd5d0f 100644 --- a/usr.sbin/smtpd/enqueue.c +++ b/usr.sbin/smtpd/enqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: enqueue.c,v 1.98 2015/10/09 15:09:09 gilles Exp $ */ +/* $OpenBSD: enqueue.c,v 1.99 2015/10/12 21:32:27 millert Exp $ */ /* * Copyright (c) 2005 Henning Brauer @@ -814,17 +814,17 @@ enqueue_offline(int argc, char *argv[], FILE *ifile, FILE *ofile) ftruncate(fileno(ofile), 0); exit(EX_SOFTWARE); } - fprintf(ofile, "%s%s", i == 1 ? "" : "|", argv[i]); + if (fprintf(ofile, "%s%s", i == 1 ? "" : "|", argv[i]) < 0) + goto write_error; } - fprintf(ofile, "\n"); + if (fputc('\n', ofile) == EOF) + goto write_error; - while ((ch = fgetc(ifile)) != EOF) - if (fputc(ch, ofile) == EOF) { - warn("write error"); - ftruncate(fileno(ofile), 0); - exit(EX_UNAVAILABLE); - } + while ((ch = fgetc(ifile)) != EOF) { + if (fputc(ch, ofile) == EOF) + goto write_error; + } if (ferror(ifile)) { warn("read error"); @@ -832,9 +832,14 @@ enqueue_offline(int argc, char *argv[], FILE *ifile, FILE *ofile) exit(EX_UNAVAILABLE); } - fclose(ofile); + if (fclose(ofile) == EOF) + goto write_error; return (EX_TEMPFAIL); +write_error: + warn("write error"); + ftruncate(fileno(ofile), 0); + exit(EX_UNAVAILABLE); } static int -- 2.20.1