summaryrefslogtreecommitdiff
path: root/usr.bin/patch/patch.c
diff options
context:
space:
mode:
authorgdt <gdt@NetBSD.org>2008-08-10 22:36:23 +0000
committergdt <gdt@NetBSD.org>2008-08-10 22:36:23 +0000
commit69bdd817ccfb1f6a541fbaf1bd792d49eec60216 (patch)
tree9d13801fd32482e5efe2745cf14f188f4377acb6 /usr.bin/patch/patch.c
parentdda0645b097129713dc66ac1ee646762858fff27 (diff)
Add error checking to use of fputs in creating output file in
temprorary directory. Previously, fputs was used without checking the return value, leading to silent truncation when the temporary filesystem was full (such as can easily happen when migrating to tmpfs).
Diffstat (limited to 'usr.bin/patch/patch.c')
-rw-r--r--usr.bin/patch/patch.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 63404f85565..b4454103021 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: patch.c,v 1.25 2007/10/14 04:54:34 lukem Exp $ */
+/* $NetBSD: patch.c,v 1.26 2008/08/10 22:36:23 gdt Exp $ */
/* patch - a program to apply diffs to original files
*
@@ -25,7 +25,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: patch.c,v 1.25 2007/10/14 04:54:34 lukem Exp $");
+__RCSID("$NetBSD: patch.c,v 1.26 2008/08/10 22:36:23 gdt Exp $");
#endif /* not lint */
#include "INTERN.h"
@@ -680,8 +680,27 @@ abort_hunk(void)
}
}
+/*
+ * Version of fputs that aborts, to replace version used in apply_hunk
+ * without checking return values.
+ */
+
+/* pacify -Wstrict-prototypes */
+int safe_fputs(const char * str, FILE * stream);
+
+int safe_fputs(const char * str, FILE * stream)
+{
+ int ret = fputs(str, stream);
+ if ( ret != 0)
+ pfatal("write(fputs) failed: %s", strerror(errno));
+ return ret; /* NOTREACHED, pacify gcc */
+}
+
/* We found where to apply it (we hope), so do it. */
+/* Use aborting version of fputs.*/
+#define fputs safe_fputs
+
static void
apply_hunk(LINENUM where)
{
@@ -799,6 +818,9 @@ apply_hunk(LINENUM where)
}
}
+/* Limit scope of fix. */
+#undef fputs
+
/* Open the new file. */
static void