summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch/patch.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-06-25 23:06:36 +0000
committerderaadt <deraadt@openbsd.org>1996-06-25 23:06:36 +0000
commitb004f8f9652eab72b5061d874d07f48c51ae35b3 (patch)
tree909f8daf075af59220e8bbac22acb4cdac74dbd3 /usr.bin/patch/patch.c
parentopen O_EXCL instead of creat; for writable rdist directories... still small DOS (diff)
downloadwireguard-openbsd-b004f8f9652eab72b5061d874d07f48c51ae35b3.tar.xz
wireguard-openbsd-b004f8f9652eab72b5061d874d07f48c51ae35b3.zip
mktemp w/ open & fdopen
Diffstat (limited to 'usr.bin/patch/patch.c')
-rw-r--r--usr.bin/patch/patch.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 2c1a65ae97f..dcfb1213cca 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: patch.c,v 1.2 1996/06/10 11:21:31 niklas Exp $ */
+/* $OpenBSD: patch.c,v 1.3 1996/06/25 23:06:39 deraadt Exp $ */
/* patch - a program to apply diffs to original files
*
@@ -9,7 +9,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: patch.c,v 1.2 1996/06/10 11:21:31 niklas Exp $";
+static char rcsid[] = "$OpenBSD: patch.c,v 1.3 1996/06/25 23:06:39 deraadt Exp $";
#endif /* not lint */
#include "INTERN.h"
@@ -784,9 +784,14 @@ void
init_output(name)
char *name;
{
- ofp = fopen(name, "w");
- if (ofp == Nullfp)
+ int fd;
+
+ if ((fd = open(name, O_EXCL|O_CREAT|O_RDWR, 0666)) == -1 ||
+ (ofp = fdopen(fd, "w")) == NULL) {
+ if (fd != -1)
+ close(fd);
pfatal2("can't create %s", name);
+ }
}
/* Open a file to put hunks we can't locate. */
@@ -795,9 +800,14 @@ void
init_reject(name)
char *name;
{
- rejfp = fopen(name, "w");
- if (rejfp == Nullfp)
+ int fd;
+
+ if ((fd = open(name, O_EXCL|O_CREAT|O_RDWR, 0666)) == -1 ||
+ (rejfp = fdopen(fd, "w")) == NULL) {
+ if (fd != -1)
+ close(fd);
pfatal2("can't create %s", name);
+ }
}
/* Copy input file to output, up to wherever hunk is to be applied. */