diff options
author | Brian Feldman <green@FreeBSD.org> | 2002-05-14 23:15:42 +0000 |
---|---|---|
committer | Brian Feldman <green@FreeBSD.org> | 2002-05-14 23:15:42 +0000 |
commit | e7b663eff21c5618f12a38a5c93e87e3599c81e3 (patch) | |
tree | 03ea6a39420b9cd16e2ddd7bb9bd6cb0e9b8d7cb /usr.bin/sed | |
parent | 661016419cc31373d53c131561825201897f02a6 (diff) | |
download | src-e7b663eff21c5618f12a38a5c93e87e3599c81e3.tar.gz src-e7b663eff21c5618f12a38a5c93e87e3599c81e3.zip |
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.
Notes
Notes:
svn path=/head/; revision=96621
Diffstat (limited to 'usr.bin/sed')
-rw-r--r-- | usr.bin/sed/main.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index cb091f45d139..2250d5a1bf64 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); |