diff options
-rw-r--r-- | usr.bin/patch/common.h | 3 | ||||
-rw-r--r-- | usr.bin/patch/inp.c | 6 | ||||
-rw-r--r-- | usr.bin/patch/patch.c | 22 | ||||
-rw-r--r-- | usr.bin/patch/pch.c | 13 |
4 files changed, 30 insertions, 14 deletions
diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h index f3fcb5b144c..2a7154c5596 100644 --- a/usr.bin/patch/common.h +++ b/usr.bin/patch/common.h @@ -1,4 +1,4 @@ -/* $OpenBSD: common.h,v 1.2 1996/06/10 11:21:26 niklas Exp $ */ +/* $OpenBSD: common.h,v 1.3 1996/06/25 23:06:36 deraadt Exp $ */ #define DEBUGGING @@ -29,6 +29,7 @@ #include <string.h> #include <assert.h> #include <sys/types.h> +#include <sys/file.h> #include <sys/stat.h> #include <ctype.h> #include <signal.h> diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index e7661358124..34a93b590a6 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,7 +1,7 @@ -/* $OpenBSD: inp.c,v 1.2 1996/06/10 11:21:28 niklas Exp $ */ +/* $OpenBSD: inp.c,v 1.3 1996/06/25 23:06:38 deraadt Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: inp.c,v 1.2 1996/06/10 11:21:28 niklas Exp $"; +static char rcsid[] = "$OpenBSD: inp.c,v 1.3 1996/06/25 23:06:38 deraadt Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -241,7 +241,7 @@ char *filename; using_plan_a = FALSE; if ((ifp = fopen(filename, "r")) == Nullfp) pfatal2("can't open file %s", filename); - if ((tifd = creat(TMPINNAME, 0666)) < 0) + if ((tifd = open(TMPINNAME, O_EXCL|O_CREAT|O_WRONLY, 0666)) < 0) pfatal2("can't open file %s", TMPINNAME); while (fgets(buf, sizeof buf, ifp) != Nullch) { if (revision != Nullch && !found_revision && rev_in_string(buf)) 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. */ diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 3d6caf2ef30..4d2200dc61a 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pch.c,v 1.2 1996/06/10 11:21:33 niklas Exp $ */ +/* $OpenBSD: pch.c,v 1.3 1996/06/25 23:06:41 deraadt Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: pch.c,v 1.2 1996/06/10 11:21:33 niklas Exp $"; +static char rcsid[] = "$OpenBSD: pch.c,v 1.3 1996/06/25 23:06:41 deraadt Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -54,10 +54,15 @@ void open_patch_file(filename) char *filename; { + int fd; + if (filename == Nullch || !*filename || strEQ(filename, "-")) { - pfp = fopen(TMPPATNAME, "w"); - if (pfp == Nullfp) + if ((fd = open(TMPPATNAME, O_EXCL|O_CREAT|O_RDWR, 0666)) == -1 || + (pfp = fdopen(fd, "w")) == NULL) { + if (fd != -1) + close(fd); pfatal2("can't create %s", TMPPATNAME); + } while (fgets(buf, sizeof buf, stdin) != Nullch) fputs(buf, pfp); Fclose(pfp); |