diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-09-15 19:19:55 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-09-15 19:19:55 +0000 |
commit | b29136b3d27d0e1e3765a81bdca933cd5953881b (patch) | |
tree | a7f8e138e2e98bf61ed712676cc2c6c3b0382360 /usr.bin | |
parent | 5f33e4ba21382f50bdc7a980885aac76fac8c71b (diff) |
Be slightly safer opening temp files.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/patch/patch.c | 16 | ||||
-rw-r--r-- | usr.bin/patch/pch.c | 10 |
2 files changed, 16 insertions, 10 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index dfbe51cba76..afb9b7307a6 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: patch.c,v 1.4 1996/07/01 20:40:09 deraadt Exp $ */ +/* $OpenBSD: patch.c,v 1.5 1996/09/15 19:19:54 millert Exp $ */ /* patch - a program to apply diffs to original files * @@ -9,7 +9,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: patch.c,v 1.4 1996/07/01 20:40:09 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: patch.c,v 1.5 1996/09/15 19:19:54 millert Exp $"; #endif /* not lint */ #include "INTERN.h" @@ -784,8 +784,10 @@ void init_output(name) char *name; { - ofp = fopen(name, "w"); - if (ofp == Nullfp) + int ofd; + + if ((ofd = open(name, O_CREAT|O_EXCL|O_WRONLY, 0600)) < 0 || + (ofp = fdopen(ofd, "w")) == Nullfp) pfatal2("can't create %s", name); } @@ -795,8 +797,10 @@ void init_reject(name) char *name; { - rejfp = fopen(name, "w"); - if (rejfp == Nullfp) + int rejfd; + + if ((rejfd = open(name, O_CREAT|O_EXCL|O_WRONLY, 0600)) < 0 || + (rejfp = fdopen(rejfd, "w")) == Nullfp) pfatal2("can't create %s", name); } diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 38225fa648a..33fbb2ec3aa 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pch.c,v 1.4 1996/07/01 20:40:10 deraadt Exp $ */ +/* $OpenBSD: pch.c,v 1.5 1996/09/15 19:19:52 millert Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: pch.c,v 1.4 1996/07/01 20:40:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: pch.c,v 1.5 1996/09/15 19:19:52 millert Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -55,8 +55,10 @@ open_patch_file(filename) char *filename; { if (filename == Nullch || !*filename || strEQ(filename, "-")) { - pfp = fopen(TMPPATNAME, "w"); - if (pfp == Nullfp) + int pfd; + + if ((pfd = open(TMPPATNAME, O_CREAT|O_EXCL|O_WRONLY, 0600)) < 0 || + (pfp = fdopen(pfd, "w")) == Nullfp) pfatal2("can't create %s", TMPPATNAME); while (fgets(buf, sizeof buf, stdin) != Nullch) fputs(buf, pfp); |