summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed/main.c
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>2002-05-14 23:15:42 +0000
committergreen <green@FreeBSD.org>2002-05-14 23:15:42 +0000
commit957e7d4f00a9759b34eeeaa7e56e0ecaf8866e71 (patch)
tree03ea6a39420b9cd16e2ddd7bb9bd6cb0e9b8d7cb /usr.bin/sed/main.c
parent61d5a9043fbea6647d345d31063ded3995f3c151 (diff)
downloadFreeBSD-src-957e7d4f00a9759b34eeeaa7e56e0ecaf8866e71.zip
FreeBSD-src-957e7d4f00a9759b34eeeaa7e56e0ecaf8866e71.tar.gz
o Clean up tmp file usage a little by using mkstemp(3) instead of
mktemp(3). It would be amazingly unlikely, but the former method could result in a symlink attack. A better solution would use ${TMPDIR}, though. o Make sed not overwrite old backup files with no warning.
Diffstat (limited to 'usr.bin/sed/main.c')
-rw-r--r--usr.bin/sed/main.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index cb091f4..2250d5a 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -434,20 +434,21 @@ inplace_edit(filename)
if (*inplace == '\0') {
char template[] = "/tmp/sed.XXXXXXXXXX";
- if (mktemp(template) == NULL)
- err(1, "mktemp");
+ output = mkstemp(template);
+ if (output == -1)
+ err(1, "mkstemp");
strlcpy(backup, template, MAXPATHLEN);
} else {
strlcpy(backup, *filename, MAXPATHLEN);
strlcat(backup, inplace, MAXPATHLEN);
+ output = open(backup, O_WRONLY | O_CREAT | O_EXCL);
+ if (output == -1)
+ err(1, "open(%s)", backup);
}
input = open(*filename, O_RDONLY);
if (input == -1)
err(1, "open(%s)", *filename);
- output = open(backup, O_WRONLY|O_CREAT);
- if (output == -1)
- err(1, "open(%s)", backup);
if (fchmod(output, orig.st_mode & ~S_IFMT) == -1)
err(1, "chmod");
buffer = malloc(orig.st_size);
OpenPOWER on IntegriCloud